event/dpaa2: fix mbuf assignment in atomic processing
[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         DPAA2_PER_LCORE_DQRR_MBUF(dqrr_index) = ev->mbuf;
201 }
202
203 static uint16_t
204 dpaa2_eventdev_dequeue_burst(void *port, struct rte_event ev[],
205                              uint16_t nb_events, uint64_t timeout_ticks)
206 {
207         const struct qbman_result *dq;
208         struct qbman_swp *swp;
209         const struct qbman_fd *fd;
210         struct dpaa2_queue *rxq;
211         int num_pkts = 0, ret, i = 0;
212
213         RTE_SET_USED(port);
214
215         if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
216                 ret = dpaa2_affine_qbman_swp();
217                 if (ret) {
218                         DPAA2_EVENTDEV_ERR("Failure in affining portal");
219                         return 0;
220                 }
221         }
222         swp = DPAA2_PER_LCORE_PORTAL;
223
224         /* Check if there are atomic contexts to be released */
225         while (DPAA2_PER_LCORE_DQRR_SIZE) {
226                 if (DPAA2_PER_LCORE_DQRR_HELD & (1 << i)) {
227                         qbman_swp_dqrr_idx_consume(swp, i);
228                         DPAA2_PER_LCORE_DQRR_SIZE--;
229                         DPAA2_PER_LCORE_DQRR_MBUF(i)->seqn =
230                                 DPAA2_INVALID_MBUF_SEQN;
231                 }
232                 i++;
233         }
234         DPAA2_PER_LCORE_DQRR_HELD = 0;
235
236         do {
237                 dq = qbman_swp_dqrr_next(swp);
238                 if (!dq) {
239                         if (!num_pkts && timeout_ticks) {
240                                 dpaa2_eventdev_dequeue_wait(timeout_ticks);
241                                 timeout_ticks = 0;
242                                 continue;
243                         }
244                         return num_pkts;
245                 }
246                 qbman_swp_prefetch_dqrr_next(swp);
247
248                 fd = qbman_result_DQ_fd(dq);
249                 rxq = (struct dpaa2_queue *)(size_t)qbman_result_DQ_fqd_ctx(dq);
250                 if (rxq) {
251                         rxq->cb(swp, fd, dq, rxq, &ev[num_pkts]);
252                 } else {
253                         qbman_swp_dqrr_consume(swp, dq);
254                         DPAA2_EVENTDEV_ERR("Null Return VQ received");
255                         return 0;
256                 }
257
258                 num_pkts++;
259         } while (num_pkts < nb_events);
260
261         return num_pkts;
262 }
263
264 static uint16_t
265 dpaa2_eventdev_dequeue(void *port, struct rte_event *ev,
266                        uint64_t timeout_ticks)
267 {
268         return dpaa2_eventdev_dequeue_burst(port, ev, 1, timeout_ticks);
269 }
270
271 static void
272 dpaa2_eventdev_info_get(struct rte_eventdev *dev,
273                         struct rte_event_dev_info *dev_info)
274 {
275         struct dpaa2_eventdev *priv = dev->data->dev_private;
276
277         EVENTDEV_INIT_FUNC_TRACE();
278
279         RTE_SET_USED(dev);
280
281         memset(dev_info, 0, sizeof(struct rte_event_dev_info));
282         dev_info->min_dequeue_timeout_ns =
283                 DPAA2_EVENT_MIN_DEQUEUE_TIMEOUT;
284         dev_info->max_dequeue_timeout_ns =
285                 DPAA2_EVENT_MAX_DEQUEUE_TIMEOUT;
286         dev_info->dequeue_timeout_ns =
287                 DPAA2_EVENT_MIN_DEQUEUE_TIMEOUT;
288         dev_info->max_event_queues = priv->max_event_queues;
289         dev_info->max_event_queue_flows =
290                 DPAA2_EVENT_MAX_QUEUE_FLOWS;
291         dev_info->max_event_queue_priority_levels =
292                 DPAA2_EVENT_MAX_QUEUE_PRIORITY_LEVELS;
293         dev_info->max_event_priority_levels =
294                 DPAA2_EVENT_MAX_EVENT_PRIORITY_LEVELS;
295         dev_info->max_event_ports = rte_fslmc_get_device_count(DPAA2_IO);
296         dev_info->max_event_port_dequeue_depth =
297                 DPAA2_EVENT_MAX_PORT_DEQUEUE_DEPTH;
298         dev_info->max_event_port_enqueue_depth =
299                 DPAA2_EVENT_MAX_PORT_ENQUEUE_DEPTH;
300         dev_info->max_num_events = DPAA2_EVENT_MAX_NUM_EVENTS;
301         dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
302                 RTE_EVENT_DEV_CAP_BURST_MODE|
303                 RTE_EVENT_DEV_CAP_RUNTIME_PORT_LINK |
304                 RTE_EVENT_DEV_CAP_MULTIPLE_QUEUE_PORT |
305                 RTE_EVENT_DEV_CAP_NONSEQ_MODE;
306
307 }
308
309 static int
310 dpaa2_eventdev_configure(const struct rte_eventdev *dev)
311 {
312         struct dpaa2_eventdev *priv = dev->data->dev_private;
313         struct rte_event_dev_config *conf = &dev->data->dev_conf;
314
315         EVENTDEV_INIT_FUNC_TRACE();
316
317         priv->dequeue_timeout_ns = conf->dequeue_timeout_ns;
318         priv->nb_event_queues = conf->nb_event_queues;
319         priv->nb_event_ports = conf->nb_event_ports;
320         priv->nb_event_queue_flows = conf->nb_event_queue_flows;
321         priv->nb_event_port_dequeue_depth = conf->nb_event_port_dequeue_depth;
322         priv->nb_event_port_enqueue_depth = conf->nb_event_port_enqueue_depth;
323         priv->event_dev_cfg = conf->event_dev_cfg;
324
325         DPAA2_EVENTDEV_DEBUG("Configured eventdev devid=%d",
326                              dev->data->dev_id);
327         return 0;
328 }
329
330 static int
331 dpaa2_eventdev_start(struct rte_eventdev *dev)
332 {
333         EVENTDEV_INIT_FUNC_TRACE();
334
335         RTE_SET_USED(dev);
336
337         return 0;
338 }
339
340 static void
341 dpaa2_eventdev_stop(struct rte_eventdev *dev)
342 {
343         EVENTDEV_INIT_FUNC_TRACE();
344
345         RTE_SET_USED(dev);
346 }
347
348 static int
349 dpaa2_eventdev_close(struct rte_eventdev *dev)
350 {
351         EVENTDEV_INIT_FUNC_TRACE();
352
353         RTE_SET_USED(dev);
354
355         return 0;
356 }
357
358 static void
359 dpaa2_eventdev_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
360                               struct rte_event_queue_conf *queue_conf)
361 {
362         EVENTDEV_INIT_FUNC_TRACE();
363
364         RTE_SET_USED(dev);
365         RTE_SET_USED(queue_id);
366         RTE_SET_USED(queue_conf);
367
368         queue_conf->nb_atomic_flows = DPAA2_EVENT_QUEUE_ATOMIC_FLOWS;
369         queue_conf->schedule_type = RTE_SCHED_TYPE_ATOMIC |
370                                       RTE_SCHED_TYPE_PARALLEL;
371         queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
372 }
373
374 static void
375 dpaa2_eventdev_queue_release(struct rte_eventdev *dev, uint8_t queue_id)
376 {
377         EVENTDEV_INIT_FUNC_TRACE();
378
379         RTE_SET_USED(dev);
380         RTE_SET_USED(queue_id);
381 }
382
383 static int
384 dpaa2_eventdev_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
385                            const struct rte_event_queue_conf *queue_conf)
386 {
387         struct dpaa2_eventdev *priv = dev->data->dev_private;
388         struct evq_info_t *evq_info =
389                 &priv->evq_info[queue_id];
390
391         EVENTDEV_INIT_FUNC_TRACE();
392
393         evq_info->event_queue_cfg = queue_conf->event_queue_cfg;
394
395         return 0;
396 }
397
398 static void
399 dpaa2_eventdev_port_def_conf(struct rte_eventdev *dev, uint8_t port_id,
400                              struct rte_event_port_conf *port_conf)
401 {
402         EVENTDEV_INIT_FUNC_TRACE();
403
404         RTE_SET_USED(dev);
405         RTE_SET_USED(port_id);
406         RTE_SET_USED(port_conf);
407
408         port_conf->new_event_threshold =
409                 DPAA2_EVENT_MAX_NUM_EVENTS;
410         port_conf->dequeue_depth =
411                 DPAA2_EVENT_MAX_PORT_DEQUEUE_DEPTH;
412         port_conf->enqueue_depth =
413                 DPAA2_EVENT_MAX_PORT_ENQUEUE_DEPTH;
414         port_conf->disable_implicit_release = 0;
415 }
416
417 static void
418 dpaa2_eventdev_port_release(void *port)
419 {
420         EVENTDEV_INIT_FUNC_TRACE();
421
422         RTE_SET_USED(port);
423 }
424
425 static int
426 dpaa2_eventdev_port_setup(struct rte_eventdev *dev, uint8_t port_id,
427                           const struct rte_event_port_conf *port_conf)
428 {
429         EVENTDEV_INIT_FUNC_TRACE();
430
431         RTE_SET_USED(port_conf);
432
433         if (!dpaa2_io_portal[port_id].dpio_dev) {
434                 dpaa2_io_portal[port_id].dpio_dev =
435                                 dpaa2_get_qbman_swp(port_id);
436                 rte_atomic16_inc(&dpaa2_io_portal[port_id].dpio_dev->ref_count);
437                 if (!dpaa2_io_portal[port_id].dpio_dev)
438                         return -1;
439         }
440
441         dpaa2_io_portal[port_id].eventdev = dev;
442         dev->data->ports[port_id] = &dpaa2_io_portal[port_id];
443         return 0;
444 }
445
446 static int
447 dpaa2_eventdev_port_unlink(struct rte_eventdev *dev, void *port,
448                            uint8_t queues[], uint16_t nb_unlinks)
449 {
450         struct dpaa2_eventdev *priv = dev->data->dev_private;
451         struct dpaa2_io_portal_t *dpaa2_portal = port;
452         struct evq_info_t *evq_info;
453         int i;
454
455         EVENTDEV_INIT_FUNC_TRACE();
456
457         for (i = 0; i < nb_unlinks; i++) {
458                 evq_info = &priv->evq_info[queues[i]];
459                 qbman_swp_push_set(dpaa2_portal->dpio_dev->sw_portal,
460                                    evq_info->dpcon->channel_index, 0);
461                 dpio_remove_static_dequeue_channel(dpaa2_portal->dpio_dev->dpio,
462                                         0, dpaa2_portal->dpio_dev->token,
463                         evq_info->dpcon->dpcon_id);
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
485                 ret = dpio_add_static_dequeue_channel(
486                         dpaa2_portal->dpio_dev->dpio,
487                         CMD_PRI_LOW, dpaa2_portal->dpio_dev->token,
488                         evq_info->dpcon->dpcon_id, &channel_index);
489                 if (ret < 0) {
490                         DPAA2_EVENTDEV_ERR(
491                                 "Static dequeue config failed: err(%d)", ret);
492                         goto err;
493                 }
494
495                 qbman_swp_push_set(dpaa2_portal->dpio_dev->sw_portal,
496                                    channel_index, 1);
497                 evq_info->dpcon->channel_index = channel_index;
498         }
499
500         RTE_SET_USED(priorities);
501
502         return (int)nb_links;
503 err:
504         for (n = 0; n < i; n++) {
505                 evq_info = &priv->evq_info[queues[n]];
506                 qbman_swp_push_set(dpaa2_portal->dpio_dev->sw_portal,
507                                    evq_info->dpcon->channel_index, 0);
508                 dpio_remove_static_dequeue_channel(dpaa2_portal->dpio_dev->dpio,
509                                         0, dpaa2_portal->dpio_dev->token,
510                         evq_info->dpcon->dpcon_id);
511         }
512         return ret;
513 }
514
515 static int
516 dpaa2_eventdev_timeout_ticks(struct rte_eventdev *dev, uint64_t ns,
517                              uint64_t *timeout_ticks)
518 {
519         uint32_t scale = 1;
520
521         EVENTDEV_INIT_FUNC_TRACE();
522
523         RTE_SET_USED(dev);
524         *timeout_ticks = ns * scale;
525
526         return 0;
527 }
528
529 static void
530 dpaa2_eventdev_dump(struct rte_eventdev *dev, FILE *f)
531 {
532         EVENTDEV_INIT_FUNC_TRACE();
533
534         RTE_SET_USED(dev);
535         RTE_SET_USED(f);
536 }
537
538 static int
539 dpaa2_eventdev_eth_caps_get(const struct rte_eventdev *dev,
540                             const struct rte_eth_dev *eth_dev,
541                             uint32_t *caps)
542 {
543         const char *ethdev_driver = eth_dev->device->driver->name;
544
545         EVENTDEV_INIT_FUNC_TRACE();
546
547         RTE_SET_USED(dev);
548
549         if (!strcmp(ethdev_driver, "net_dpaa2"))
550                 *caps = RTE_EVENT_ETH_RX_ADAPTER_DPAA2_CAP;
551         else
552                 *caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
553
554         return 0;
555 }
556
557 static int
558 dpaa2_eventdev_eth_queue_add_all(const struct rte_eventdev *dev,
559                 const struct rte_eth_dev *eth_dev,
560                 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
561 {
562         struct dpaa2_eventdev *priv = dev->data->dev_private;
563         uint8_t ev_qid = queue_conf->ev.queue_id;
564         uint16_t dpcon_id = priv->evq_info[ev_qid].dpcon->dpcon_id;
565         int i, ret;
566
567         EVENTDEV_INIT_FUNC_TRACE();
568
569         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
570                 ret = dpaa2_eth_eventq_attach(eth_dev, i,
571                                 dpcon_id, queue_conf);
572                 if (ret) {
573                         DPAA2_EVENTDEV_ERR(
574                                 "Event queue attach failed: err(%d)", ret);
575                         goto fail;
576                 }
577         }
578         return 0;
579 fail:
580         for (i = (i - 1); i >= 0 ; i--)
581                 dpaa2_eth_eventq_detach(eth_dev, i);
582
583         return ret;
584 }
585
586 static int
587 dpaa2_eventdev_eth_queue_add(const struct rte_eventdev *dev,
588                 const struct rte_eth_dev *eth_dev,
589                 int32_t rx_queue_id,
590                 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
591 {
592         struct dpaa2_eventdev *priv = dev->data->dev_private;
593         uint8_t ev_qid = queue_conf->ev.queue_id;
594         uint16_t dpcon_id = priv->evq_info[ev_qid].dpcon->dpcon_id;
595         int ret;
596
597         EVENTDEV_INIT_FUNC_TRACE();
598
599         if (rx_queue_id == -1)
600                 return dpaa2_eventdev_eth_queue_add_all(dev,
601                                 eth_dev, queue_conf);
602
603         ret = dpaa2_eth_eventq_attach(eth_dev, rx_queue_id,
604                         dpcon_id, queue_conf);
605         if (ret) {
606                 DPAA2_EVENTDEV_ERR(
607                         "Event queue attach failed: err(%d)", ret);
608                 return ret;
609         }
610         return 0;
611 }
612
613 static int
614 dpaa2_eventdev_eth_queue_del_all(const struct rte_eventdev *dev,
615                              const struct rte_eth_dev *eth_dev)
616 {
617         int i, ret;
618
619         EVENTDEV_INIT_FUNC_TRACE();
620
621         RTE_SET_USED(dev);
622
623         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
624                 ret = dpaa2_eth_eventq_detach(eth_dev, i);
625                 if (ret) {
626                         DPAA2_EVENTDEV_ERR(
627                                 "Event queue detach failed: err(%d)", ret);
628                         return ret;
629                 }
630         }
631
632         return 0;
633 }
634
635 static int
636 dpaa2_eventdev_eth_queue_del(const struct rte_eventdev *dev,
637                              const struct rte_eth_dev *eth_dev,
638                              int32_t rx_queue_id)
639 {
640         int ret;
641
642         EVENTDEV_INIT_FUNC_TRACE();
643
644         if (rx_queue_id == -1)
645                 return dpaa2_eventdev_eth_queue_del_all(dev, eth_dev);
646
647         ret = dpaa2_eth_eventq_detach(eth_dev, rx_queue_id);
648         if (ret) {
649                 DPAA2_EVENTDEV_ERR(
650                         "Event queue detach failed: err(%d)", ret);
651                 return ret;
652         }
653
654         return 0;
655 }
656
657 static int
658 dpaa2_eventdev_eth_start(const struct rte_eventdev *dev,
659                          const struct rte_eth_dev *eth_dev)
660 {
661         EVENTDEV_INIT_FUNC_TRACE();
662
663         RTE_SET_USED(dev);
664         RTE_SET_USED(eth_dev);
665
666         return 0;
667 }
668
669 static int
670 dpaa2_eventdev_eth_stop(const struct rte_eventdev *dev,
671                         const struct rte_eth_dev *eth_dev)
672 {
673         EVENTDEV_INIT_FUNC_TRACE();
674
675         RTE_SET_USED(dev);
676         RTE_SET_USED(eth_dev);
677
678         return 0;
679 }
680
681 static struct rte_eventdev_ops dpaa2_eventdev_ops = {
682         .dev_infos_get    = dpaa2_eventdev_info_get,
683         .dev_configure    = dpaa2_eventdev_configure,
684         .dev_start        = dpaa2_eventdev_start,
685         .dev_stop         = dpaa2_eventdev_stop,
686         .dev_close        = dpaa2_eventdev_close,
687         .queue_def_conf   = dpaa2_eventdev_queue_def_conf,
688         .queue_setup      = dpaa2_eventdev_queue_setup,
689         .queue_release    = dpaa2_eventdev_queue_release,
690         .port_def_conf    = dpaa2_eventdev_port_def_conf,
691         .port_setup       = dpaa2_eventdev_port_setup,
692         .port_release     = dpaa2_eventdev_port_release,
693         .port_link        = dpaa2_eventdev_port_link,
694         .port_unlink      = dpaa2_eventdev_port_unlink,
695         .timeout_ticks    = dpaa2_eventdev_timeout_ticks,
696         .dump             = dpaa2_eventdev_dump,
697         .eth_rx_adapter_caps_get = dpaa2_eventdev_eth_caps_get,
698         .eth_rx_adapter_queue_add = dpaa2_eventdev_eth_queue_add,
699         .eth_rx_adapter_queue_del = dpaa2_eventdev_eth_queue_del,
700         .eth_rx_adapter_start = dpaa2_eventdev_eth_start,
701         .eth_rx_adapter_stop = dpaa2_eventdev_eth_stop,
702 };
703
704 static int
705 dpaa2_eventdev_setup_dpci(struct dpaa2_dpci_dev *dpci_dev,
706                           struct dpaa2_dpcon_dev *dpcon_dev)
707 {
708         struct dpci_rx_queue_cfg rx_queue_cfg;
709         int ret, i;
710
711         /*Do settings to get the frame on a DPCON object*/
712         rx_queue_cfg.options = DPCI_QUEUE_OPT_DEST |
713                   DPCI_QUEUE_OPT_USER_CTX;
714         rx_queue_cfg.dest_cfg.dest_type = DPCI_DEST_DPCON;
715         rx_queue_cfg.dest_cfg.dest_id = dpcon_dev->dpcon_id;
716         rx_queue_cfg.dest_cfg.priority = DPAA2_EVENT_DEFAULT_DPCI_PRIO;
717
718         dpci_dev->rx_queue[DPAA2_EVENT_DPCI_PARALLEL_QUEUE].cb =
719                 dpaa2_eventdev_process_parallel;
720         dpci_dev->rx_queue[DPAA2_EVENT_DPCI_ATOMIC_QUEUE].cb =
721                 dpaa2_eventdev_process_atomic;
722
723         for (i = 0 ; i < DPAA2_EVENT_DPCI_MAX_QUEUES; i++) {
724                 rx_queue_cfg.user_ctx = (size_t)(&dpci_dev->rx_queue[i]);
725                 ret = dpci_set_rx_queue(&dpci_dev->dpci,
726                                         CMD_PRI_LOW,
727                                         dpci_dev->token, i,
728                                         &rx_queue_cfg);
729                 if (ret) {
730                         DPAA2_EVENTDEV_ERR(
731                                 "DPCI Rx queue setup failed: err(%d)",
732                                 ret);
733                         return ret;
734                 }
735         }
736         return 0;
737 }
738
739 static int
740 dpaa2_eventdev_create(const char *name)
741 {
742         struct rte_eventdev *eventdev;
743         struct dpaa2_eventdev *priv;
744         struct dpaa2_dpcon_dev *dpcon_dev = NULL;
745         struct dpaa2_dpci_dev *dpci_dev = NULL;
746         int ret;
747
748         eventdev = rte_event_pmd_vdev_init(name,
749                                            sizeof(struct dpaa2_eventdev),
750                                            rte_socket_id());
751         if (eventdev == NULL) {
752                 DPAA2_EVENTDEV_ERR("Failed to create Event device %s", name);
753                 goto fail;
754         }
755
756         eventdev->dev_ops       = &dpaa2_eventdev_ops;
757         eventdev->enqueue       = dpaa2_eventdev_enqueue;
758         eventdev->enqueue_burst = dpaa2_eventdev_enqueue_burst;
759         eventdev->enqueue_new_burst = dpaa2_eventdev_enqueue_burst;
760         eventdev->enqueue_forward_burst = dpaa2_eventdev_enqueue_burst;
761         eventdev->dequeue       = dpaa2_eventdev_dequeue;
762         eventdev->dequeue_burst = dpaa2_eventdev_dequeue_burst;
763
764         /* For secondary processes, the primary has done all the work */
765         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
766                 return 0;
767
768         priv = eventdev->data->dev_private;
769         priv->max_event_queues = 0;
770
771         do {
772                 dpcon_dev = rte_dpaa2_alloc_dpcon_dev();
773                 if (!dpcon_dev)
774                         break;
775                 priv->evq_info[priv->max_event_queues].dpcon = dpcon_dev;
776
777                 dpci_dev = rte_dpaa2_alloc_dpci_dev();
778                 if (!dpci_dev) {
779                         rte_dpaa2_free_dpcon_dev(dpcon_dev);
780                         break;
781                 }
782                 priv->evq_info[priv->max_event_queues].dpci = dpci_dev;
783
784                 ret = dpaa2_eventdev_setup_dpci(dpci_dev, dpcon_dev);
785                 if (ret) {
786                         DPAA2_EVENTDEV_ERR(
787                                     "DPCI setup failed: err(%d)", ret);
788                         return ret;
789                 }
790                 priv->max_event_queues++;
791         } while (dpcon_dev && dpci_dev);
792
793         return 0;
794 fail:
795         return -EFAULT;
796 }
797
798 static int
799 dpaa2_eventdev_probe(struct rte_vdev_device *vdev)
800 {
801         const char *name;
802
803         name = rte_vdev_device_name(vdev);
804         DPAA2_EVENTDEV_INFO("Initializing %s", name);
805         return dpaa2_eventdev_create(name);
806 }
807
808 static int
809 dpaa2_eventdev_remove(struct rte_vdev_device *vdev)
810 {
811         const char *name;
812
813         name = rte_vdev_device_name(vdev);
814         DPAA2_EVENTDEV_INFO("Closing %s", name);
815
816         return rte_event_pmd_vdev_uninit(name);
817 }
818
819 static struct rte_vdev_driver vdev_eventdev_dpaa2_pmd = {
820         .probe = dpaa2_eventdev_probe,
821         .remove = dpaa2_eventdev_remove
822 };
823
824 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_DPAA2_PMD, vdev_eventdev_dpaa2_pmd);
825
826 RTE_INIT(dpaa2_eventdev_init_log)
827 {
828         dpaa2_logtype_event = rte_log_register("pmd.event.dpaa2");
829         if (dpaa2_logtype_event >= 0)
830                 rte_log_set_level(dpaa2_logtype_event, RTE_LOG_NOTICE);
831 }