eal: remove sys/queue.h from public headers
[dpdk.git] / drivers / bus / dpaa / dpaa_bus.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright 2017-2020 NXP
4  *
5  */
6 /* System headers */
7 #include <stdio.h>
8 #include <inttypes.h>
9 #include <unistd.h>
10 #include <limits.h>
11 #include <sched.h>
12 #include <signal.h>
13 #include <pthread.h>
14 #include <sys/types.h>
15 #include <sys/eventfd.h>
16
17 #include <rte_byteorder.h>
18 #include <rte_common.h>
19 #include <rte_interrupts.h>
20 #include <rte_log.h>
21 #include <rte_debug.h>
22 #include <rte_atomic.h>
23 #include <rte_branch_prediction.h>
24 #include <rte_memory.h>
25 #include <rte_tailq.h>
26 #include <rte_eal.h>
27 #include <rte_alarm.h>
28 #include <rte_ether.h>
29 #include <ethdev_driver.h>
30 #include <rte_malloc.h>
31 #include <rte_ring.h>
32 #include <rte_bus.h>
33 #include <rte_mbuf_pool_ops.h>
34 #include <rte_mbuf_dyn.h>
35
36 #include <dpaa_of.h>
37 #include <rte_dpaa_bus.h>
38 #include <rte_dpaa_logs.h>
39 #include <dpaax_iova_table.h>
40
41 #include <fsl_usd.h>
42 #include <fsl_qman.h>
43 #include <fsl_bman.h>
44 #include <netcfg.h>
45
46 static struct rte_dpaa_bus rte_dpaa_bus;
47 struct netcfg_info *dpaa_netcfg;
48
49 /* define a variable to hold the portal_key, once created.*/
50 static pthread_key_t dpaa_portal_key;
51
52 unsigned int dpaa_svr_family;
53
54 #define FSL_DPAA_BUS_NAME       dpaa_bus
55
56 RTE_DEFINE_PER_LCORE(struct dpaa_portal *, dpaa_io);
57
58 #define DPAA_SEQN_DYNFIELD_NAME "dpaa_seqn_dynfield"
59 int dpaa_seqn_dynfield_offset = -1;
60
61 struct fm_eth_port_cfg *
62 dpaa_get_eth_port_cfg(int dev_id)
63 {
64         return &dpaa_netcfg->port_cfg[dev_id];
65 }
66
67 static int
68 compare_dpaa_devices(struct rte_dpaa_device *dev1,
69                      struct rte_dpaa_device *dev2)
70 {
71         int comp = 0;
72
73         /* Segragating ETH from SEC devices */
74         if (dev1->device_type > dev2->device_type)
75                 comp = 1;
76         else if (dev1->device_type < dev2->device_type)
77                 comp = -1;
78         else
79                 comp = 0;
80
81         if ((comp != 0) || (dev1->device_type != FSL_DPAA_ETH))
82                 return comp;
83
84         if (dev1->id.fman_id > dev2->id.fman_id) {
85                 comp = 1;
86         } else if (dev1->id.fman_id < dev2->id.fman_id) {
87                 comp = -1;
88         } else {
89                 /* FMAN ids match, check for mac_id */
90                 if (dev1->id.mac_id > dev2->id.mac_id)
91                         comp = 1;
92                 else if (dev1->id.mac_id < dev2->id.mac_id)
93                         comp = -1;
94                 else
95                         comp = 0;
96         }
97
98         return comp;
99 }
100
101 static inline void
102 dpaa_add_to_device_list(struct rte_dpaa_device *newdev)
103 {
104         int comp, inserted = 0;
105         struct rte_dpaa_device *dev = NULL;
106         struct rte_dpaa_device *tdev = NULL;
107
108         RTE_TAILQ_FOREACH_SAFE(dev, &rte_dpaa_bus.device_list, next, tdev) {
109                 comp = compare_dpaa_devices(newdev, dev);
110                 if (comp < 0) {
111                         TAILQ_INSERT_BEFORE(dev, newdev, next);
112                         inserted = 1;
113                         break;
114                 }
115         }
116
117         if (!inserted)
118                 TAILQ_INSERT_TAIL(&rte_dpaa_bus.device_list, newdev, next);
119 }
120
121 /*
122  * Reads the SEC device from DTS
123  * Returns -1 if SEC devices not available, 0 otherwise
124  */
125 static inline int
126 dpaa_sec_available(void)
127 {
128         const struct device_node *caam_node;
129
130         for_each_compatible_node(caam_node, NULL, "fsl,sec-v4.0") {
131                 return 0;
132         }
133
134         return -1;
135 }
136
137 static void dpaa_clean_device_list(void);
138
139 static struct rte_devargs *
140 dpaa_devargs_lookup(struct rte_dpaa_device *dev)
141 {
142         struct rte_devargs *devargs;
143         char dev_name[32];
144
145         RTE_EAL_DEVARGS_FOREACH("dpaa_bus", devargs) {
146                 devargs->bus->parse(devargs->name, &dev_name);
147                 if (strcmp(dev_name, dev->device.name) == 0) {
148                         DPAA_BUS_INFO("**Devargs matched %s", dev_name);
149                         return devargs;
150                 }
151         }
152         return NULL;
153 }
154
155 static int
156 dpaa_create_device_list(void)
157 {
158         int i;
159         int ret;
160         struct rte_dpaa_device *dev;
161         struct fm_eth_port_cfg *cfg;
162         struct fman_if *fman_intf;
163
164         /* Creating Ethernet Devices */
165         for (i = 0; i < dpaa_netcfg->num_ethports; i++) {
166                 dev = calloc(1, sizeof(struct rte_dpaa_device));
167                 if (!dev) {
168                         DPAA_BUS_LOG(ERR, "Failed to allocate ETH devices");
169                         ret = -ENOMEM;
170                         goto cleanup;
171                 }
172
173                 dev->device.bus = &rte_dpaa_bus.bus;
174
175                 cfg = &dpaa_netcfg->port_cfg[i];
176                 fman_intf = cfg->fman_if;
177
178                 /* Device identifiers */
179                 dev->id.fman_id = fman_intf->fman_idx + 1;
180                 dev->id.mac_id = fman_intf->mac_idx;
181                 dev->device_type = FSL_DPAA_ETH;
182                 dev->id.dev_id = i;
183
184                 /* Create device name */
185                 memset(dev->name, 0, RTE_ETH_NAME_MAX_LEN);
186                 sprintf(dev->name, "fm%d-mac%d", (fman_intf->fman_idx + 1),
187                         fman_intf->mac_idx);
188                 DPAA_BUS_LOG(INFO, "%s netdev added", dev->name);
189                 dev->device.name = dev->name;
190                 dev->device.devargs = dpaa_devargs_lookup(dev);
191
192                 dpaa_add_to_device_list(dev);
193         }
194
195         rte_dpaa_bus.device_count = i;
196
197         /* Unlike case of ETH, RTE_LIBRTE_DPAA_MAX_CRYPTODEV SEC devices are
198          * constantly created only if "sec" property is found in the device
199          * tree. Logically there is no limit for number of devices (QI
200          * interfaces) that can be created.
201          */
202
203         if (dpaa_sec_available()) {
204                 DPAA_BUS_LOG(INFO, "DPAA SEC devices are not available");
205                 return 0;
206         }
207
208         /* Creating SEC Devices */
209         for (i = 0; i < RTE_LIBRTE_DPAA_MAX_CRYPTODEV; i++) {
210                 dev = calloc(1, sizeof(struct rte_dpaa_device));
211                 if (!dev) {
212                         DPAA_BUS_LOG(ERR, "Failed to allocate SEC devices");
213                         ret = -1;
214                         goto cleanup;
215                 }
216
217                 dev->device_type = FSL_DPAA_CRYPTO;
218                 dev->id.dev_id = rte_dpaa_bus.device_count + i;
219
220                 /* Even though RTE_CRYPTODEV_NAME_MAX_LEN is valid length of
221                  * crypto PMD, using RTE_ETH_NAME_MAX_LEN as that is the size
222                  * allocated for dev->name/
223                  */
224                 memset(dev->name, 0, RTE_ETH_NAME_MAX_LEN);
225                 sprintf(dev->name, "dpaa_sec-%d", i+1);
226                 DPAA_BUS_LOG(INFO, "%s cryptodev added", dev->name);
227                 dev->device.name = dev->name;
228                 dev->device.devargs = dpaa_devargs_lookup(dev);
229
230                 dpaa_add_to_device_list(dev);
231         }
232
233         rte_dpaa_bus.device_count += i;
234
235         return 0;
236
237 cleanup:
238         dpaa_clean_device_list();
239         return ret;
240 }
241
242 static void
243 dpaa_clean_device_list(void)
244 {
245         struct rte_dpaa_device *dev = NULL;
246         struct rte_dpaa_device *tdev = NULL;
247
248         RTE_TAILQ_FOREACH_SAFE(dev, &rte_dpaa_bus.device_list, next, tdev) {
249                 TAILQ_REMOVE(&rte_dpaa_bus.device_list, dev, next);
250                 free(dev);
251                 dev = NULL;
252         }
253 }
254
255 int rte_dpaa_portal_init(void *arg)
256 {
257         static const struct rte_mbuf_dynfield dpaa_seqn_dynfield_desc = {
258                 .name = DPAA_SEQN_DYNFIELD_NAME,
259                 .size = sizeof(dpaa_seqn_t),
260                 .align = __alignof__(dpaa_seqn_t),
261         };
262         unsigned int cpu, lcore = rte_lcore_id();
263         int ret;
264
265         BUS_INIT_FUNC_TRACE();
266
267         if ((size_t)arg == 1 || lcore == LCORE_ID_ANY)
268                 lcore = rte_get_main_lcore();
269         else
270                 if (lcore >= RTE_MAX_LCORE)
271                         return -1;
272
273         cpu = rte_lcore_to_cpu_id(lcore);
274
275         dpaa_seqn_dynfield_offset =
276                 rte_mbuf_dynfield_register(&dpaa_seqn_dynfield_desc);
277         if (dpaa_seqn_dynfield_offset < 0) {
278                 DPAA_BUS_LOG(ERR, "Failed to register mbuf field for dpaa sequence number\n");
279                 return -rte_errno;
280         }
281
282         /* Initialise bman thread portals */
283         ret = bman_thread_init();
284         if (ret) {
285                 DPAA_BUS_LOG(ERR, "bman_thread_init failed on core %u"
286                              " (lcore=%u) with ret: %d", cpu, lcore, ret);
287                 return ret;
288         }
289
290         DPAA_BUS_LOG(DEBUG, "BMAN thread initialized - CPU=%d lcore=%d",
291                      cpu, lcore);
292
293         /* Initialise qman thread portals */
294         ret = qman_thread_init();
295         if (ret) {
296                 DPAA_BUS_LOG(ERR, "qman_thread_init failed on core %u"
297                             " (lcore=%u) with ret: %d", cpu, lcore, ret);
298                 bman_thread_finish();
299                 return ret;
300         }
301
302         DPAA_BUS_LOG(DEBUG, "QMAN thread initialized - CPU=%d lcore=%d",
303                      cpu, lcore);
304
305         DPAA_PER_LCORE_PORTAL = rte_malloc(NULL, sizeof(struct dpaa_portal),
306                                     RTE_CACHE_LINE_SIZE);
307         if (!DPAA_PER_LCORE_PORTAL) {
308                 DPAA_BUS_LOG(ERR, "Unable to allocate memory");
309                 bman_thread_finish();
310                 qman_thread_finish();
311                 return -ENOMEM;
312         }
313
314         DPAA_PER_LCORE_PORTAL->qman_idx = qman_get_portal_index();
315         DPAA_PER_LCORE_PORTAL->bman_idx = bman_get_portal_index();
316         DPAA_PER_LCORE_PORTAL->tid = rte_gettid();
317
318         ret = pthread_setspecific(dpaa_portal_key,
319                                   (void *)DPAA_PER_LCORE_PORTAL);
320         if (ret) {
321                 DPAA_BUS_LOG(ERR, "pthread_setspecific failed on core %u"
322                              " (lcore=%u) with ret: %d", cpu, lcore, ret);
323                 dpaa_portal_finish(NULL);
324
325                 return ret;
326         }
327
328         DPAA_BUS_LOG(DEBUG, "QMAN thread initialized");
329
330         return 0;
331 }
332
333 int
334 rte_dpaa_portal_fq_init(void *arg, struct qman_fq *fq)
335 {
336         /* Affine above created portal with channel*/
337         u32 sdqcr;
338         int ret;
339
340         if (unlikely(!DPAA_PER_LCORE_PORTAL)) {
341                 ret = rte_dpaa_portal_init(arg);
342                 if (ret < 0) {
343                         DPAA_BUS_LOG(ERR, "portal initialization failure");
344                         return ret;
345                 }
346         }
347
348         /* Initialise qman specific portals */
349         ret = fsl_qman_fq_portal_init(fq->qp);
350         if (ret) {
351                 DPAA_BUS_LOG(ERR, "Unable to init fq portal");
352                 return -1;
353         }
354
355         sdqcr = QM_SDQCR_CHANNELS_POOL_CONV(fq->ch_id);
356         qman_static_dequeue_add(sdqcr, fq->qp);
357
358         return 0;
359 }
360
361 int rte_dpaa_portal_fq_close(struct qman_fq *fq)
362 {
363         return fsl_qman_fq_portal_destroy(fq->qp);
364 }
365
366 void
367 dpaa_portal_finish(void *arg)
368 {
369         struct dpaa_portal *dpaa_io_portal = (struct dpaa_portal *)arg;
370
371         if (!dpaa_io_portal) {
372                 DPAA_BUS_LOG(DEBUG, "Portal already cleaned");
373                 return;
374         }
375
376         bman_thread_finish();
377         qman_thread_finish();
378
379         pthread_setspecific(dpaa_portal_key, NULL);
380
381         rte_free(dpaa_io_portal);
382         dpaa_io_portal = NULL;
383         DPAA_PER_LCORE_PORTAL = NULL;
384 }
385
386 static int
387 rte_dpaa_bus_parse(const char *name, void *out)
388 {
389         unsigned int i, j;
390         size_t delta;
391
392         /* There are two ways of passing device name, with and without
393          * separator. "dpaa_bus:fm1-mac3" with separator, and "fm1-mac3"
394          * without separator. Both need to be handled.
395          * It is also possible that "name=fm1-mac3" is passed along.
396          */
397         DPAA_BUS_DEBUG("Parse device name (%s)", name);
398
399         delta = 0;
400         if (strncmp(name, "dpaa_bus:", 9) == 0) {
401                 delta = 9;
402         } else if (strncmp(name, "name=", 5) == 0) {
403                 delta = 5;
404         }
405
406         if (sscanf(&name[delta], "fm%u-mac%u", &i, &j) != 2 ||
407             i >= 2 || j >= 16) {
408                 return -EINVAL;
409         }
410
411         if (out != NULL) {
412                 char *out_name = out;
413                 const size_t max_name_len = sizeof("fm.-mac..") - 1;
414
415                 /* Do not check for truncation, either name ends with
416                  * '\0' or the device name is followed by parameters and there
417                  * will be a ',' instead. Not copying past this comma is not an
418                  * error.
419                  */
420                 strlcpy(out_name, &name[delta], max_name_len + 1);
421
422                 /* Second digit of mac%u could instead be ','. */
423                 if ((strlen(out_name) == max_name_len) &&
424                     out_name[max_name_len] == ',')
425                         out_name[max_name_len] = '\0';
426         }
427
428         return 0;
429 }
430
431 #define DPAA_DEV_PATH1 "/sys/devices/platform/soc/soc:fsl,dpaa"
432 #define DPAA_DEV_PATH2 "/sys/devices/platform/fsl,dpaa"
433
434 static int
435 rte_dpaa_bus_scan(void)
436 {
437         int ret;
438
439         BUS_INIT_FUNC_TRACE();
440
441         if ((access(DPAA_DEV_PATH1, F_OK) != 0) &&
442             (access(DPAA_DEV_PATH2, F_OK) != 0)) {
443                 RTE_LOG(DEBUG, EAL, "DPAA Bus not present. Skipping.\n");
444                 return 0;
445         }
446
447         if (rte_dpaa_bus.detected)
448                 return 0;
449
450         rte_dpaa_bus.detected = 1;
451
452         /* create the key, supplying a function that'll be invoked
453          * when a portal affined thread will be deleted.
454          */
455         ret = pthread_key_create(&dpaa_portal_key, dpaa_portal_finish);
456         if (ret) {
457                 DPAA_BUS_LOG(DEBUG, "Unable to create pthread key. (%d)", ret);
458                 dpaa_clean_device_list();
459                 return ret;
460         }
461
462         return 0;
463 }
464
465 /* register a dpaa bus based dpaa driver */
466 void
467 rte_dpaa_driver_register(struct rte_dpaa_driver *driver)
468 {
469         RTE_VERIFY(driver);
470
471         BUS_INIT_FUNC_TRACE();
472
473         TAILQ_INSERT_TAIL(&rte_dpaa_bus.driver_list, driver, next);
474         /* Update Bus references */
475         driver->dpaa_bus = &rte_dpaa_bus;
476 }
477
478 /* un-register a dpaa bus based dpaa driver */
479 void
480 rte_dpaa_driver_unregister(struct rte_dpaa_driver *driver)
481 {
482         struct rte_dpaa_bus *dpaa_bus;
483
484         BUS_INIT_FUNC_TRACE();
485
486         dpaa_bus = driver->dpaa_bus;
487
488         TAILQ_REMOVE(&dpaa_bus->driver_list, driver, next);
489         /* Update Bus references */
490         driver->dpaa_bus = NULL;
491 }
492
493 static int
494 rte_dpaa_device_match(struct rte_dpaa_driver *drv,
495                       struct rte_dpaa_device *dev)
496 {
497         if (!drv || !dev) {
498                 DPAA_BUS_DEBUG("Invalid drv or dev received.");
499                 return -1;
500         }
501
502         if (drv->drv_type == dev->device_type)
503                 return 0;
504
505         return -1;
506 }
507
508 static int
509 rte_dpaa_bus_dev_build(void)
510 {
511         int ret;
512
513         /* Load the device-tree driver */
514         ret = of_init();
515         if (ret) {
516                 DPAA_BUS_LOG(ERR, "of_init failed with ret: %d", ret);
517                 return -1;
518         }
519
520         /* Get the interface configurations from device-tree */
521         dpaa_netcfg = netcfg_acquire();
522         if (!dpaa_netcfg) {
523                 DPAA_BUS_LOG(ERR,
524                         "netcfg failed: /dev/fsl_usdpaa device not available");
525                 DPAA_BUS_WARN(
526                         "Check if you are using USDPAA based device tree");
527                 return -EINVAL;
528         }
529
530         RTE_LOG(NOTICE, EAL, "DPAA Bus Detected\n");
531
532         if (!dpaa_netcfg->num_ethports) {
533                 DPAA_BUS_LOG(INFO, "NO DPDK mapped net interfaces available");
534                 /* This is not an error */
535         }
536
537 #ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
538         dump_netcfg(dpaa_netcfg);
539 #endif
540
541         DPAA_BUS_LOG(DEBUG, "Number of ethernet devices = %d",
542                      dpaa_netcfg->num_ethports);
543         ret = dpaa_create_device_list();
544         if (ret) {
545                 DPAA_BUS_LOG(ERR, "Unable to create device list. (%d)", ret);
546                 return ret;
547         }
548         return 0;
549 }
550
551 static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle)
552 {
553         int fd;
554
555         fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
556         if (fd < 0) {
557                 DPAA_BUS_ERR("Cannot set up eventfd, error %i (%s)",
558                              errno, strerror(errno));
559                 return errno;
560         }
561
562         intr_handle->fd = fd;
563         intr_handle->type = RTE_INTR_HANDLE_EXT;
564
565         return 0;
566 }
567
568 static int
569 rte_dpaa_bus_probe(void)
570 {
571         int ret = -1;
572         struct rte_dpaa_device *dev;
573         struct rte_dpaa_driver *drv;
574         FILE *svr_file = NULL;
575         unsigned int svr_ver;
576         int probe_all = rte_dpaa_bus.bus.conf.scan_mode != RTE_BUS_SCAN_ALLOWLIST;
577         static int process_once;
578
579         /* If DPAA bus is not present nothing needs to be done */
580         if (!rte_dpaa_bus.detected)
581                 return 0;
582
583         /* Device list creation is only done once */
584         if (!process_once) {
585                 rte_dpaa_bus_dev_build();
586                 /* One time load of Qman/Bman drivers */
587                 ret = qman_global_init();
588                 if (ret) {
589                         DPAA_BUS_ERR("QMAN initialization failed: %d",
590                                      ret);
591                         return ret;
592                 }
593                 ret = bman_global_init();
594                 if (ret) {
595                         DPAA_BUS_ERR("BMAN initialization failed: %d",
596                                      ret);
597                         return ret;
598                 }
599         }
600         process_once = 1;
601
602         /* If no device present on DPAA bus nothing needs to be done */
603         if (TAILQ_EMPTY(&rte_dpaa_bus.device_list))
604                 return 0;
605
606         svr_file = fopen(DPAA_SOC_ID_FILE, "r");
607         if (svr_file) {
608                 if (fscanf(svr_file, "svr:%x", &svr_ver) > 0)
609                         dpaa_svr_family = svr_ver & SVR_MASK;
610                 fclose(svr_file);
611         }
612
613         TAILQ_FOREACH(dev, &rte_dpaa_bus.device_list, next) {
614                 if (dev->device_type == FSL_DPAA_ETH) {
615                         ret = rte_dpaa_setup_intr(&dev->intr_handle);
616                         if (ret)
617                                 DPAA_BUS_ERR("Error setting up interrupt.\n");
618                 }
619         }
620
621         /* And initialize the PA->VA translation table */
622         dpaax_iova_table_populate();
623
624         /* For each registered driver, and device, call the driver->probe */
625         TAILQ_FOREACH(dev, &rte_dpaa_bus.device_list, next) {
626                 TAILQ_FOREACH(drv, &rte_dpaa_bus.driver_list, next) {
627                         ret = rte_dpaa_device_match(drv, dev);
628                         if (ret)
629                                 continue;
630
631                         if (rte_dev_is_probed(&dev->device))
632                                 continue;
633
634                         if (!drv->probe ||
635                             (dev->device.devargs &&
636                              dev->device.devargs->policy == RTE_DEV_BLOCKED))
637                                 continue;
638
639                         if (probe_all ||
640                             (dev->device.devargs &&
641                              dev->device.devargs->policy == RTE_DEV_ALLOWED)) {
642                                 ret = drv->probe(drv, dev);
643                                 if (ret) {
644                                         DPAA_BUS_ERR("unable to probe:%s",
645                                                      dev->name);
646                                 } else {
647                                         dev->driver = drv;
648                                         dev->device.driver = &drv->driver;
649                                 }
650                         }
651                         break;
652                 }
653         }
654
655         /* Register DPAA mempool ops only if any DPAA device has
656          * been detected.
657          */
658         rte_mbuf_set_platform_mempool_ops(DPAA_MEMPOOL_OPS_NAME);
659
660         return 0;
661 }
662
663 static struct rte_device *
664 rte_dpaa_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
665                      const void *data)
666 {
667         struct rte_dpaa_device *dev;
668         const struct rte_dpaa_device *dstart;
669
670         /* find_device is called with 'data' as an opaque object - just call
671          * cmp with this and each device object on bus.
672          */
673
674         if (start != NULL) {
675                 dstart = RTE_DEV_TO_DPAA_CONST(start);
676                 dev = TAILQ_NEXT(dstart, next);
677         } else {
678                 dev = TAILQ_FIRST(&rte_dpaa_bus.device_list);
679         }
680
681         while (dev != NULL) {
682                 if (cmp(&dev->device, data) == 0) {
683                         DPAA_BUS_DEBUG("Found dev=(%s)\n", dev->device.name);
684                         return &dev->device;
685                 }
686                 dev = TAILQ_NEXT(dev, next);
687         }
688
689         DPAA_BUS_DEBUG("Unable to find any device\n");
690         return NULL;
691 }
692
693 /*
694  * Get iommu class of DPAA2 devices on the bus.
695  */
696 static enum rte_iova_mode
697 rte_dpaa_get_iommu_class(void)
698 {
699         if ((access(DPAA_DEV_PATH1, F_OK) != 0) &&
700             (access(DPAA_DEV_PATH2, F_OK) != 0)) {
701                 return RTE_IOVA_DC;
702         }
703         return RTE_IOVA_PA;
704 }
705
706 static int
707 dpaa_bus_plug(struct rte_device *dev __rte_unused)
708 {
709         /* No operation is performed while plugging the device */
710         return 0;
711 }
712
713 static int
714 dpaa_bus_unplug(struct rte_device *dev __rte_unused)
715 {
716         /* No operation is performed while unplugging the device */
717         return 0;
718 }
719
720 static void *
721 dpaa_bus_dev_iterate(const void *start, const char *str,
722                      const struct rte_dev_iterator *it __rte_unused)
723 {
724         const struct rte_dpaa_device *dstart;
725         struct rte_dpaa_device *dev;
726         char *dup, *dev_name = NULL;
727
728         if (str == NULL) {
729                 DPAA_BUS_DEBUG("No device string");
730                 return NULL;
731         }
732
733         /* Expectation is that device would be name=device_name */
734         if (strncmp(str, "name=", 5) != 0) {
735                 DPAA_BUS_DEBUG("Invalid device string (%s)\n", str);
736                 return NULL;
737         }
738
739         /* Now that name=device_name format is available, split */
740         dup = strdup(str);
741         dev_name = dup + strlen("name=");
742
743         if (start != NULL) {
744                 dstart = RTE_DEV_TO_DPAA_CONST(start);
745                 dev = TAILQ_NEXT(dstart, next);
746         } else {
747                 dev = TAILQ_FIRST(&rte_dpaa_bus.device_list);
748         }
749
750         while (dev != NULL) {
751                 if (strcmp(dev->device.name, dev_name) == 0) {
752                         free(dup);
753                         return &dev->device;
754                 }
755                 dev = TAILQ_NEXT(dev, next);
756         }
757
758         free(dup);
759         return NULL;
760 }
761
762 static struct rte_dpaa_bus rte_dpaa_bus = {
763         .bus = {
764                 .scan = rte_dpaa_bus_scan,
765                 .probe = rte_dpaa_bus_probe,
766                 .parse = rte_dpaa_bus_parse,
767                 .find_device = rte_dpaa_find_device,
768                 .get_iommu_class = rte_dpaa_get_iommu_class,
769                 .plug = dpaa_bus_plug,
770                 .unplug = dpaa_bus_unplug,
771                 .dev_iterate = dpaa_bus_dev_iterate,
772         },
773         .device_list = TAILQ_HEAD_INITIALIZER(rte_dpaa_bus.device_list),
774         .driver_list = TAILQ_HEAD_INITIALIZER(rte_dpaa_bus.driver_list),
775         .device_count = 0,
776 };
777
778 RTE_REGISTER_BUS(FSL_DPAA_BUS_NAME, rte_dpaa_bus.bus);
779 RTE_LOG_REGISTER_DEFAULT(dpaa_logtype_bus, NOTICE);