1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2015-2016 Freescale Semiconductor, Inc. All rights reserved.
4 * Copyright 2016-2019 NXP
10 #include <sys/types.h>
15 #include <sys/ioctl.h>
21 #include <sys/eventfd.h>
23 #include <eal_filesystem.h>
25 #include <rte_ethdev_driver.h>
26 #include <rte_malloc.h>
27 #include <rte_memcpy.h>
28 #include <rte_string_fns.h>
29 #include <rte_cycles.h>
30 #include <rte_kvargs.h>
33 #include <rte_eal_memconfig.h>
35 #include "rte_fslmc.h"
36 #include "fslmc_vfio.h"
37 #include "fslmc_logs.h"
38 #include <mc/fsl_dpmng.h>
40 #include "portal/dpaa2_hw_pvt.h"
41 #include "portal/dpaa2_hw_dpio.h"
43 #define FSLMC_CONTAINER_MAX_LEN 8 /**< Of the format dprc.XX */
45 /* Number of VFIO containers & groups with in */
46 static struct fslmc_vfio_group vfio_group;
47 static struct fslmc_vfio_container vfio_container;
48 static int container_device_fd;
49 char *fslmc_container;
50 static int fslmc_iommu_type;
51 static uint32_t *msi_intr_vaddr;
52 void *(*rte_mcp_ptr_list);
54 static struct rte_dpaa2_object_list dpaa2_obj_list =
55 TAILQ_HEAD_INITIALIZER(dpaa2_obj_list);
57 /*register a fslmc bus based dpaa2 driver */
59 rte_fslmc_object_register(struct rte_dpaa2_object *object)
63 TAILQ_INSERT_TAIL(&dpaa2_obj_list, object, next);
67 fslmc_get_container_group(int *groupid)
72 if (!fslmc_container) {
73 container = getenv("DPRC");
74 if (container == NULL) {
75 DPAA2_BUS_DEBUG("DPAA2: DPRC not available");
79 if (strlen(container) >= FSLMC_CONTAINER_MAX_LEN) {
80 DPAA2_BUS_ERR("Invalid container name: %s", container);
84 fslmc_container = strdup(container);
85 if (!fslmc_container) {
86 DPAA2_BUS_ERR("Mem alloc failure; Container name");
91 fslmc_iommu_type = (rte_vfio_noiommu_is_enabled() == 1) ?
92 RTE_VFIO_NOIOMMU : VFIO_TYPE1_IOMMU;
94 /* get group number */
95 ret = rte_vfio_get_group_num(SYSFS_FSL_MC_DEVICES,
96 fslmc_container, groupid);
98 DPAA2_BUS_ERR("Unable to find %s IOMMU group", fslmc_container);
102 DPAA2_BUS_DEBUG("Container: %s has VFIO iommu group id = %d",
103 fslmc_container, *groupid);
109 vfio_connect_container(void)
113 if (vfio_container.used) {
114 DPAA2_BUS_DEBUG("No container available");
118 /* Try connecting to vfio container if already created */
119 if (!ioctl(vfio_group.fd, VFIO_GROUP_SET_CONTAINER,
120 &vfio_container.fd)) {
122 "Container pre-exists with FD[0x%x] for this group",
124 vfio_group.container = &vfio_container;
128 /* Opens main vfio file descriptor which represents the "container" */
129 fd = rte_vfio_get_container_fd();
131 DPAA2_BUS_ERR("Failed to open VFIO container");
135 /* Check whether support for SMMU type IOMMU present or not */
136 if (ioctl(fd, VFIO_CHECK_EXTENSION, fslmc_iommu_type)) {
137 /* Connect group to container */
138 ret = ioctl(vfio_group.fd, VFIO_GROUP_SET_CONTAINER, &fd);
140 DPAA2_BUS_ERR("Failed to setup group container");
145 ret = ioctl(fd, VFIO_SET_IOMMU, fslmc_iommu_type);
147 DPAA2_BUS_ERR("Failed to setup VFIO iommu");
152 DPAA2_BUS_ERR("No supported IOMMU available");
157 vfio_container.used = 1;
158 vfio_container.fd = fd;
159 vfio_container.group = &vfio_group;
160 vfio_group.container = &vfio_container;
165 static int vfio_map_irq_region(struct fslmc_vfio_group *group)
168 unsigned long *vaddr = NULL;
169 struct vfio_iommu_type1_dma_map map = {
170 .argsz = sizeof(map),
171 .flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE,
177 vaddr = (unsigned long *)mmap(NULL, 0x1000, PROT_WRITE |
178 PROT_READ, MAP_SHARED, container_device_fd, 0x6030000);
179 if (vaddr == MAP_FAILED) {
180 DPAA2_BUS_INFO("Unable to map region (errno = %d)", errno);
184 msi_intr_vaddr = (uint32_t *)((char *)(vaddr) + 64);
185 map.vaddr = (unsigned long)vaddr;
186 ret = ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA, &map);
190 DPAA2_BUS_ERR("Unable to map DMA address (errno = %d)", errno);
194 static int fslmc_map_dma(uint64_t vaddr, rte_iova_t iovaddr, size_t len);
195 static int fslmc_unmap_dma(uint64_t vaddr, rte_iova_t iovaddr, size_t len);
198 fslmc_memevent_cb(enum rte_mem_event type, const void *addr, size_t len,
199 void *arg __rte_unused)
201 struct rte_memseg_list *msl;
202 struct rte_memseg *ms;
203 size_t cur_len = 0, map_len = 0;
205 rte_iova_t iova_addr;
208 msl = rte_mem_virt2memseg_list(addr);
210 while (cur_len < len) {
211 const void *va = RTE_PTR_ADD(addr, cur_len);
213 ms = rte_mem_virt2memseg(va, msl);
214 iova_addr = ms->iova;
215 virt_addr = ms->addr_64;
218 DPAA2_BUS_DEBUG("Request for %s, va=%p, "
219 "virt_addr=0x%" PRIx64 ", "
220 "iova=0x%" PRIx64 ", map_len=%zu",
221 type == RTE_MEM_EVENT_ALLOC ?
223 va, virt_addr, iova_addr, map_len);
225 /* iova_addr may be set to RTE_BAD_IOVA */
226 if (iova_addr == RTE_BAD_IOVA) {
227 DPAA2_BUS_DEBUG("Segment has invalid iova, skipping\n");
232 if (type == RTE_MEM_EVENT_ALLOC)
233 ret = fslmc_map_dma(virt_addr, iova_addr, map_len);
235 ret = fslmc_unmap_dma(virt_addr, iova_addr, map_len);
238 DPAA2_BUS_ERR("DMA Mapping/Unmapping failed. "
239 "Map=%d, addr=%p, len=%zu, err:(%d)",
240 type, va, map_len, ret);
247 if (type == RTE_MEM_EVENT_ALLOC)
248 DPAA2_BUS_DEBUG("Total Mapped: addr=%p, len=%zu",
251 DPAA2_BUS_DEBUG("Total Unmapped: addr=%p, len=%zu",
256 fslmc_map_dma(uint64_t vaddr, rte_iova_t iovaddr __rte_unused, size_t len)
258 struct fslmc_vfio_group *group;
259 struct vfio_iommu_type1_dma_map dma_map = {
260 .argsz = sizeof(struct vfio_iommu_type1_dma_map),
261 .flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE,
265 if (fslmc_iommu_type == RTE_VFIO_NOIOMMU) {
266 DPAA2_BUS_DEBUG("Running in NOIOMMU mode");
271 dma_map.vaddr = vaddr;
273 #ifdef RTE_LIBRTE_DPAA2_USE_PHYS_IOVA
274 dma_map.iova = iovaddr;
276 dma_map.iova = dma_map.vaddr;
279 /* SET DMA MAP for IOMMU */
282 if (!group->container) {
283 DPAA2_BUS_ERR("Container is not connected ");
287 DPAA2_BUS_DEBUG("--> Map address: 0x%"PRIx64", size: %"PRIu64"",
288 (uint64_t)dma_map.vaddr, (uint64_t)dma_map.size);
289 ret = ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA, &dma_map);
291 DPAA2_BUS_ERR("VFIO_IOMMU_MAP_DMA API(errno = %d)",
300 fslmc_unmap_dma(uint64_t vaddr, uint64_t iovaddr __rte_unused, size_t len)
302 struct fslmc_vfio_group *group;
303 struct vfio_iommu_type1_dma_unmap dma_unmap = {
304 .argsz = sizeof(struct vfio_iommu_type1_dma_unmap),
309 if (fslmc_iommu_type == RTE_VFIO_NOIOMMU) {
310 DPAA2_BUS_DEBUG("Running in NOIOMMU mode");
314 dma_unmap.size = len;
315 dma_unmap.iova = vaddr;
317 /* SET DMA MAP for IOMMU */
320 if (!group->container) {
321 DPAA2_BUS_ERR("Container is not connected ");
325 DPAA2_BUS_DEBUG("--> Unmap address: 0x%"PRIx64", size: %"PRIu64"",
326 (uint64_t)dma_unmap.iova, (uint64_t)dma_unmap.size);
327 ret = ioctl(group->container->fd, VFIO_IOMMU_UNMAP_DMA, &dma_unmap);
329 DPAA2_BUS_ERR("VFIO_IOMMU_UNMAP_DMA API(errno = %d)",
338 fslmc_dmamap_seg(const struct rte_memseg_list *msl __rte_unused,
339 const struct rte_memseg *ms, void *arg)
344 /* if IOVA address is invalid, skip */
345 if (ms->iova == RTE_BAD_IOVA)
348 ret = fslmc_map_dma(ms->addr_64, ms->iova, ms->len);
350 DPAA2_BUS_ERR("Unable to VFIO map (addr=%p, len=%zu)",
359 rte_fslmc_vfio_mem_dmamap(uint64_t vaddr, uint64_t iova, uint64_t size)
362 struct fslmc_vfio_group *group;
363 struct vfio_iommu_type1_dma_map dma_map = {
364 .argsz = sizeof(struct vfio_iommu_type1_dma_map),
365 .flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE,
368 if (fslmc_iommu_type == RTE_VFIO_NOIOMMU) {
369 DPAA2_BUS_DEBUG("Running in NOIOMMU mode");
373 /* SET DMA MAP for IOMMU */
375 if (!group->container) {
376 DPAA2_BUS_ERR("Container is not connected");
381 dma_map.vaddr = vaddr;
384 DPAA2_BUS_DEBUG("VFIOdmamap 0x%"PRIx64":0x%"PRIx64",size 0x%"PRIx64"\n",
385 (uint64_t)dma_map.vaddr, (uint64_t)dma_map.iova,
386 (uint64_t)dma_map.size);
387 ret = ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA,
390 printf("Unable to map DMA address (errno = %d)\n",
398 int rte_fslmc_vfio_dmamap(void)
402 /* Lock before parsing and registering callback to memory subsystem */
403 rte_mcfg_mem_read_lock();
405 if (rte_memseg_walk(fslmc_dmamap_seg, &i) < 0) {
406 rte_mcfg_mem_read_unlock();
410 ret = rte_mem_event_callback_register("fslmc_memevent_clb",
411 fslmc_memevent_cb, NULL);
412 if (ret && rte_errno == ENOTSUP)
413 DPAA2_BUS_DEBUG("Memory event callbacks not supported");
415 DPAA2_BUS_DEBUG("Unable to install memory handler");
417 DPAA2_BUS_DEBUG("Installed memory callback handler");
419 DPAA2_BUS_DEBUG("Total %d segments found.", i);
421 /* TODO - This is a W.A. as VFIO currently does not add the mapping of
422 * the interrupt region to SMMU. This should be removed once the
423 * support is added in the Kernel.
425 vfio_map_irq_region(&vfio_group);
427 /* Existing segments have been mapped and memory callback for hotplug
428 * has been installed.
430 rte_mcfg_mem_read_unlock();
436 fslmc_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
437 int *vfio_dev_fd, struct vfio_device_info *device_info)
439 struct vfio_group_status group_status = {
440 .argsz = sizeof(group_status)
442 int vfio_group_fd, vfio_container_fd, iommu_group_no, ret;
444 /* get group number */
445 ret = rte_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_no);
449 /* get the actual group fd */
450 vfio_group_fd = rte_vfio_get_group_fd(iommu_group_no);
451 if (vfio_group_fd < 0)
454 /* if group_fd == 0, that means the device isn't managed by VFIO */
455 if (vfio_group_fd == 0) {
456 RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n",
461 /* Opens main vfio file descriptor which represents the "container" */
462 vfio_container_fd = rte_vfio_get_container_fd();
463 if (vfio_container_fd < 0) {
464 DPAA2_BUS_ERR("Failed to open VFIO container");
468 /* check if the group is viable */
469 ret = ioctl(vfio_group_fd, VFIO_GROUP_GET_STATUS, &group_status);
471 DPAA2_BUS_ERR(" %s cannot get group status, "
472 "error %i (%s)\n", dev_addr,
473 errno, strerror(errno));
474 close(vfio_group_fd);
475 rte_vfio_clear_group(vfio_group_fd);
477 } else if (!(group_status.flags & VFIO_GROUP_FLAGS_VIABLE)) {
478 DPAA2_BUS_ERR(" %s VFIO group is not viable!\n", dev_addr);
479 close(vfio_group_fd);
480 rte_vfio_clear_group(vfio_group_fd);
483 /* At this point, we know that this group is viable (meaning,
484 * all devices are either bound to VFIO or not bound to anything)
487 /* check if group does not have a container yet */
488 if (!(group_status.flags & VFIO_GROUP_FLAGS_CONTAINER_SET)) {
490 /* add group to a container */
491 ret = ioctl(vfio_group_fd, VFIO_GROUP_SET_CONTAINER,
494 DPAA2_BUS_ERR(" %s cannot add VFIO group to container, "
495 "error %i (%s)\n", dev_addr,
496 errno, strerror(errno));
497 close(vfio_group_fd);
498 close(vfio_container_fd);
499 rte_vfio_clear_group(vfio_group_fd);
504 * set an IOMMU type for container
507 if (ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION,
509 ret = ioctl(vfio_container_fd, VFIO_SET_IOMMU,
512 DPAA2_BUS_ERR("Failed to setup VFIO iommu");
513 close(vfio_group_fd);
514 close(vfio_container_fd);
518 DPAA2_BUS_ERR("No supported IOMMU available");
519 close(vfio_group_fd);
520 close(vfio_container_fd);
525 /* get a file descriptor for the device */
526 *vfio_dev_fd = ioctl(vfio_group_fd, VFIO_GROUP_GET_DEVICE_FD, dev_addr);
527 if (*vfio_dev_fd < 0) {
528 /* if we cannot get a device fd, this implies a problem with
529 * the VFIO group or the container not having IOMMU configured.
532 DPAA2_BUS_WARN("Getting a vfio_dev_fd for %s failed", dev_addr);
533 close(vfio_group_fd);
534 close(vfio_container_fd);
535 rte_vfio_clear_group(vfio_group_fd);
539 /* test and setup the device */
540 ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
542 DPAA2_BUS_ERR(" %s cannot get device info, error %i (%s)",
543 dev_addr, errno, strerror(errno));
545 close(vfio_group_fd);
546 close(vfio_container_fd);
547 rte_vfio_clear_group(vfio_group_fd);
554 static intptr_t vfio_map_mcp_obj(const char *mcp_obj)
556 intptr_t v_addr = (intptr_t)MAP_FAILED;
558 struct vfio_group_status status = { .argsz = sizeof(status) };
560 struct vfio_device_info d_info = { .argsz = sizeof(d_info) };
561 struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) };
563 fslmc_vfio_setup_device(SYSFS_FSL_MC_DEVICES, mcp_obj,
566 /* getting device region info*/
567 ret = ioctl(mc_fd, VFIO_DEVICE_GET_REGION_INFO, ®_info);
569 DPAA2_BUS_ERR("Error in VFIO getting REGION_INFO");
573 v_addr = (size_t)mmap(NULL, reg_info.size,
574 PROT_WRITE | PROT_READ, MAP_SHARED,
575 mc_fd, reg_info.offset);
583 #define IRQ_SET_BUF_LEN (sizeof(struct vfio_irq_set) + sizeof(int))
585 int rte_dpaa2_intr_enable(struct rte_intr_handle *intr_handle, int index)
588 char irq_set_buf[IRQ_SET_BUF_LEN];
589 struct vfio_irq_set *irq_set;
592 len = sizeof(irq_set_buf);
594 irq_set = (struct vfio_irq_set *)irq_set_buf;
595 irq_set->argsz = len;
598 VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
599 irq_set->index = index;
601 fd_ptr = (int *)&irq_set->data;
602 *fd_ptr = intr_handle->fd;
604 ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
606 DPAA2_BUS_ERR("Error:dpaa2 SET IRQs fd=%d, err = %d(%s)",
607 intr_handle->fd, errno, strerror(errno));
614 int rte_dpaa2_intr_disable(struct rte_intr_handle *intr_handle, int index)
616 struct vfio_irq_set *irq_set;
617 char irq_set_buf[IRQ_SET_BUF_LEN];
620 len = sizeof(struct vfio_irq_set);
622 irq_set = (struct vfio_irq_set *)irq_set_buf;
623 irq_set->argsz = len;
624 irq_set->flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_TRIGGER;
625 irq_set->index = index;
629 ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
632 "Error disabling dpaa2 interrupts for fd %d",
638 /* set up interrupt support (but not enable interrupts) */
640 rte_dpaa2_vfio_setup_intr(struct rte_intr_handle *intr_handle,
646 /* start from MSI-X interrupt type */
647 for (i = 0; i < num_irqs; i++) {
648 struct vfio_irq_info irq_info = { .argsz = sizeof(irq_info) };
653 ret = ioctl(vfio_dev_fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info);
655 DPAA2_BUS_ERR("Cannot get IRQ(%d) info, error %i (%s)",
656 i, errno, strerror(errno));
660 /* if this vector cannot be used with eventfd,
661 * fail if we explicitly
662 * specified interrupt type, otherwise continue
664 if ((irq_info.flags & VFIO_IRQ_INFO_EVENTFD) == 0)
667 /* set up an eventfd for interrupts */
668 fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
670 DPAA2_BUS_ERR("Cannot set up eventfd, error %i (%s)",
671 errno, strerror(errno));
675 intr_handle->fd = fd;
676 intr_handle->type = RTE_INTR_HANDLE_VFIO_MSI;
677 intr_handle->vfio_dev_fd = vfio_dev_fd;
682 /* if we're here, we haven't found a suitable interrupt vector */
687 * fslmc_process_iodevices for processing only IO (ETH, CRYPTO, and possibly
691 fslmc_process_iodevices(struct rte_dpaa2_device *dev)
694 struct vfio_device_info device_info = { .argsz = sizeof(device_info) };
695 struct rte_dpaa2_object *object = NULL;
697 fslmc_vfio_setup_device(SYSFS_FSL_MC_DEVICES, dev->device.name,
698 &dev_fd, &device_info);
700 switch (dev->dev_type) {
702 rte_dpaa2_vfio_setup_intr(&dev->intr_handle, dev_fd,
703 device_info.num_irqs);
711 TAILQ_FOREACH(object, &dpaa2_obj_list, next) {
712 if (dev->dev_type == object->dev_type)
713 object->create(dev_fd, &device_info,
723 DPAA2_BUS_LOG(DEBUG, "Device (%s) abstracted from VFIO",
729 fslmc_process_mcp(struct rte_dpaa2_device *dev)
733 char *dev_name = NULL;
734 struct fsl_mc_io dpmng = {0};
735 struct mc_version mc_ver_info = {0};
737 rte_mcp_ptr_list = malloc(sizeof(void *) * 1);
738 if (!rte_mcp_ptr_list) {
739 DPAA2_BUS_ERR("Unable to allocate MC portal memory");
744 dev_name = strdup(dev->device.name);
746 DPAA2_BUS_ERR("Unable to allocate MC device name memory");
751 v_addr = vfio_map_mcp_obj(dev->device.name);
752 if (v_addr == (intptr_t)MAP_FAILED) {
753 DPAA2_BUS_ERR("Error mapping region (errno = %d)", errno);
758 /* check the MC version compatibility */
759 dpmng.regs = (void *)v_addr;
761 /* In case of secondary processes, MC version check is no longer
764 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
765 rte_mcp_ptr_list[0] = (void *)v_addr;
769 if (mc_get_version(&dpmng, CMD_PRI_LOW, &mc_ver_info)) {
770 DPAA2_BUS_ERR("Unable to obtain MC version");
775 if ((mc_ver_info.major != MC_VER_MAJOR) ||
776 (mc_ver_info.minor < MC_VER_MINOR)) {
777 DPAA2_BUS_ERR("DPAA2 MC version not compatible!"
778 " Expected %d.%d.x, Detected %d.%d.%d",
779 MC_VER_MAJOR, MC_VER_MINOR,
780 mc_ver_info.major, mc_ver_info.minor,
781 mc_ver_info.revision);
785 rte_mcp_ptr_list[0] = (void *)v_addr;
794 if (rte_mcp_ptr_list) {
795 free(rte_mcp_ptr_list);
796 rte_mcp_ptr_list = NULL;
803 fslmc_vfio_process_group(void)
806 int found_mportal = 0;
807 struct rte_dpaa2_device *dev, *dev_temp;
809 /* Search the MCP as that should be initialized first. */
810 TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, dev_temp) {
811 if (dev->dev_type == DPAA2_MPORTAL) {
812 if (dev->device.devargs &&
813 dev->device.devargs->policy == RTE_DEV_BLACKLISTED) {
814 DPAA2_BUS_LOG(DEBUG, "%s Blacklisted, skipping",
816 TAILQ_REMOVE(&rte_fslmc_bus.device_list,
821 ret = fslmc_process_mcp(dev);
823 DPAA2_BUS_ERR("Unable to map MC Portal");
829 TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next);
832 /* Ideally there is only a single dpmcp, but in case
833 * multiple exists, looping on remaining devices.
838 /* Cannot continue if there is not even a single mportal */
839 if (!found_mportal) {
840 DPAA2_BUS_ERR("No MC Portal device found. Not continuing");
844 TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, dev_temp) {
845 if (dev->device.devargs &&
846 dev->device.devargs->policy == RTE_DEV_BLACKLISTED) {
847 DPAA2_BUS_LOG(DEBUG, "%s Blacklisted, skipping",
849 TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next);
852 switch (dev->dev_type) {
856 ret = fslmc_process_iodevices(dev);
858 DPAA2_BUS_DEBUG("Dev (%s) init failed",
868 /* IN case of secondary processes, all control objects
869 * like dpbp, dpcon, dpci are not initialized/required
870 * - all of these are assumed to be initialized and made
871 * available by primary.
873 if (rte_eal_process_type() == RTE_PROC_SECONDARY)
876 /* Call the object creation routine and remove the
877 * device entry from device list
879 ret = fslmc_process_iodevices(dev);
881 DPAA2_BUS_DEBUG("Dev (%s) init failed",
888 ret = fslmc_process_iodevices(dev);
890 DPAA2_BUS_DEBUG("Dev (%s) init failed",
898 /* Unknown - ignore */
899 DPAA2_BUS_DEBUG("Found unknown device (%s)",
901 TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next);
911 fslmc_vfio_setup_group(void)
915 struct vfio_group_status status = { .argsz = sizeof(status) };
917 /* if already done once */
918 if (container_device_fd)
921 ret = fslmc_get_container_group(&groupid);
925 /* In case this group was already opened, continue without any
928 if (vfio_group.groupid == groupid) {
929 DPAA2_BUS_ERR("groupid already exists %d", groupid);
933 /* Get the actual group fd */
934 ret = rte_vfio_get_group_fd(groupid);
939 /* Check group viability */
940 ret = ioctl(vfio_group.fd, VFIO_GROUP_GET_STATUS, &status);
942 DPAA2_BUS_ERR("VFIO error getting group status");
943 close(vfio_group.fd);
944 rte_vfio_clear_group(vfio_group.fd);
948 if (!(status.flags & VFIO_GROUP_FLAGS_VIABLE)) {
949 DPAA2_BUS_ERR("VFIO group not viable");
950 close(vfio_group.fd);
951 rte_vfio_clear_group(vfio_group.fd);
954 /* Since Group is VIABLE, Store the groupid */
955 vfio_group.groupid = groupid;
957 /* check if group does not have a container yet */
958 if (!(status.flags & VFIO_GROUP_FLAGS_CONTAINER_SET)) {
959 /* Now connect this IOMMU group to given container */
960 ret = vfio_connect_container();
963 "Error connecting container with groupid %d",
965 close(vfio_group.fd);
966 rte_vfio_clear_group(vfio_group.fd);
971 /* Get Device information */
972 ret = ioctl(vfio_group.fd, VFIO_GROUP_GET_DEVICE_FD, fslmc_container);
974 DPAA2_BUS_ERR("Error getting device %s fd from group %d",
975 fslmc_container, vfio_group.groupid);
976 close(vfio_group.fd);
977 rte_vfio_clear_group(vfio_group.fd);
980 container_device_fd = ret;
981 DPAA2_BUS_DEBUG("VFIO Container FD is [0x%X]",
982 container_device_fd);