49bb670c815a11ee410271aa7d61b7cabd2e7281
[dpdk.git] / drivers / bus / fslmc / fslmc_vfio.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) 2015-2016 Freescale Semiconductor, Inc. All rights reserved.
5  *   Copyright (c) 2016 NXP. All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Freescale Semiconductor, Inc nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <unistd.h>
35 #include <stdio.h>
36 #include <sys/types.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <fcntl.h>
40 #include <errno.h>
41 #include <sys/ioctl.h>
42 #include <sys/stat.h>
43 #include <sys/types.h>
44 #include <sys/mman.h>
45 #include <sys/vfs.h>
46 #include <libgen.h>
47 #include <dirent.h>
48 #include <sys/eventfd.h>
49
50 #include <rte_mbuf.h>
51 #include <rte_ethdev.h>
52 #include <rte_malloc.h>
53 #include <rte_memcpy.h>
54 #include <rte_string_fns.h>
55 #include <rte_cycles.h>
56 #include <rte_kvargs.h>
57 #include <rte_dev.h>
58 #include <rte_ethdev.h>
59 #include <rte_bus.h>
60
61 #include "rte_fslmc.h"
62 #include "fslmc_vfio.h"
63
64 #include "portal/dpaa2_hw_pvt.h"
65 #include "portal/dpaa2_hw_dpio.h"
66
67 #define VFIO_MAX_CONTAINERS     1
68
69 #define FSLMC_VFIO_LOG(level, fmt, args...) \
70         RTE_LOG(level, EAL, "%s(): " fmt "\n", __func__, ##args)
71
72 /** Pathname of FSL-MC devices directory. */
73 #define SYSFS_FSL_MC_DEVICES "/sys/bus/fsl-mc/devices"
74
75 /* Number of VFIO containers & groups with in */
76 static struct fslmc_vfio_group vfio_groups[VFIO_MAX_GRP];
77 static struct fslmc_vfio_container vfio_containers[VFIO_MAX_CONTAINERS];
78 static int container_device_fd;
79 static uint32_t *msi_intr_vaddr;
80 void *(*rte_mcp_ptr_list);
81 static uint32_t mcp_id;
82 static int is_dma_done;
83
84 static int vfio_connect_container(struct fslmc_vfio_group *vfio_group)
85 {
86         struct fslmc_vfio_container *container;
87         int i, fd, ret;
88
89         /* Try connecting to vfio container if already created */
90         for (i = 0; i < VFIO_MAX_CONTAINERS; i++) {
91                 container = &vfio_containers[i];
92                 if (!ioctl(vfio_group->fd, VFIO_GROUP_SET_CONTAINER,
93                            &container->fd)) {
94                         FSLMC_VFIO_LOG(INFO,
95                             "Container pre-exists with FD[0x%x] for this group",
96                             container->fd);
97                         vfio_group->container = container;
98                         return 0;
99                 }
100         }
101
102         /* Opens main vfio file descriptor which represents the "container" */
103         fd = vfio_get_container_fd();
104         if (fd < 0) {
105                 FSLMC_VFIO_LOG(ERR, "Failed to open VFIO container");
106                 return -errno;
107         }
108
109         /* Check whether support for SMMU type IOMMU present or not */
110         if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) {
111                 /* Connect group to container */
112                 ret = ioctl(vfio_group->fd, VFIO_GROUP_SET_CONTAINER, &fd);
113                 if (ret) {
114                         FSLMC_VFIO_LOG(ERR, "Failed to setup group container");
115                         close(fd);
116                         return -errno;
117                 }
118
119                 ret = ioctl(fd, VFIO_SET_IOMMU, VFIO_TYPE1_IOMMU);
120                 if (ret) {
121                         FSLMC_VFIO_LOG(ERR, "Failed to setup VFIO iommu");
122                         close(fd);
123                         return -errno;
124                 }
125         } else {
126                 FSLMC_VFIO_LOG(ERR, "No supported IOMMU available");
127                 close(fd);
128                 return -EINVAL;
129         }
130
131         container = NULL;
132         for (i = 0; i < VFIO_MAX_CONTAINERS; i++) {
133                 if (vfio_containers[i].used)
134                         continue;
135                 container = &vfio_containers[i];
136         }
137         if (!container) {
138                 FSLMC_VFIO_LOG(ERR, "No free container found");
139                 close(fd);
140                 return -ENOMEM;
141         }
142
143         container->used = 1;
144         container->fd = fd;
145         container->group_list[container->index] = vfio_group;
146         vfio_group->container = container;
147         container->index++;
148         return 0;
149 }
150
151 static int vfio_map_irq_region(struct fslmc_vfio_group *group)
152 {
153         int ret;
154         unsigned long *vaddr = NULL;
155         struct vfio_iommu_type1_dma_map map = {
156                 .argsz = sizeof(map),
157                 .flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE,
158                 .vaddr = 0x6030000,
159                 .iova = 0x6030000,
160                 .size = 0x1000,
161         };
162
163         vaddr = (unsigned long *)mmap(NULL, 0x1000, PROT_WRITE |
164                 PROT_READ, MAP_SHARED, container_device_fd, 0x6030000);
165         if (vaddr == MAP_FAILED) {
166                 FSLMC_VFIO_LOG(ERR, "Unable to map region (errno = %d)", errno);
167                 return -errno;
168         }
169
170         msi_intr_vaddr = (uint32_t *)((char *)(vaddr) + 64);
171         map.vaddr = (unsigned long)vaddr;
172         ret = ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA, &map);
173         if (ret == 0)
174                 return 0;
175
176         FSLMC_VFIO_LOG(ERR, "VFIO_IOMMU_MAP_DMA fails (errno = %d)", errno);
177         return -errno;
178 }
179
180 int vfio_dmamap_mem_region(uint64_t vaddr,
181                            uint64_t iova,
182                            uint64_t size)
183 {
184         struct fslmc_vfio_group *group;
185         struct vfio_iommu_type1_dma_map dma_map = {
186                 .argsz = sizeof(dma_map),
187                 .flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE,
188         };
189
190         dma_map.vaddr = vaddr;
191         dma_map.size = size;
192         dma_map.iova = iova;
193
194         /* SET DMA MAP for IOMMU */
195         group = &vfio_groups[0];
196         if (ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA, &dma_map)) {
197                 FSLMC_VFIO_LOG(ERR, "VFIO_IOMMU_MAP_DMA (errno = %d)", errno);
198                 return -1;
199         }
200         return 0;
201 }
202
203 int rte_fslmc_vfio_dmamap(void)
204 {
205         int ret;
206         struct fslmc_vfio_group *group;
207         struct vfio_iommu_type1_dma_map dma_map = {
208                 .argsz = sizeof(struct vfio_iommu_type1_dma_map),
209                 .flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE,
210         };
211
212         int i;
213         const struct rte_memseg *memseg;
214
215         if (is_dma_done)
216                 return 0;
217
218         memseg = rte_eal_get_physmem_layout();
219         if (memseg == NULL) {
220                 FSLMC_VFIO_LOG(ERR, "Cannot get physical layout.");
221                 return -ENODEV;
222         }
223
224         for (i = 0; i < RTE_MAX_MEMSEG; i++) {
225                 if (memseg[i].addr == NULL && memseg[i].len == 0) {
226                         FSLMC_VFIO_LOG(DEBUG, "Total %d segments found.", i);
227                         break;
228                 }
229
230                 dma_map.size = memseg[i].len;
231                 dma_map.vaddr = memseg[i].addr_64;
232 #ifdef RTE_LIBRTE_DPAA2_USE_PHYS_IOVA
233                 dma_map.iova = memseg[i].phys_addr;
234 #else
235                 dma_map.iova = dma_map.vaddr;
236 #endif
237
238                 /* SET DMA MAP for IOMMU */
239                 group = &vfio_groups[0];
240
241                 if (!group->container) {
242                         FSLMC_VFIO_LOG(ERR, "Container is not connected ");
243                         return -1;
244                 }
245
246                 FSLMC_VFIO_LOG(DEBUG, "-->Initial SHM Virtual ADDR %llX",
247                              dma_map.vaddr);
248                 FSLMC_VFIO_LOG(DEBUG, "-----> DMA size 0x%llX", dma_map.size);
249                 ret = ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA,
250                             &dma_map);
251                 if (ret) {
252                         FSLMC_VFIO_LOG(ERR, "VFIO_IOMMU_MAP_DMA API(errno = %d)",
253                                        errno);
254                         return ret;
255                 }
256         }
257
258         /* Verifying that at least single segment is available */
259         if (i <= 0) {
260                 FSLMC_VFIO_LOG(ERR, "No Segments found for VFIO Mapping");
261                 return -1;
262         }
263
264         /* TODO - This is a W.A. as VFIO currently does not add the mapping of
265          * the interrupt region to SMMU. This should be removed once the
266          * support is added in the Kernel.
267          */
268         vfio_map_irq_region(group);
269
270         is_dma_done = 1;
271
272         return 0;
273 }
274
275 static int64_t vfio_map_mcp_obj(struct fslmc_vfio_group *group, char *mcp_obj)
276 {
277         int64_t v_addr = (int64_t)MAP_FAILED;
278         int32_t ret, mc_fd;
279
280         struct vfio_device_info d_info = { .argsz = sizeof(d_info) };
281         struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) };
282
283         /* getting the mcp object's fd*/
284         mc_fd = ioctl(group->fd, VFIO_GROUP_GET_DEVICE_FD, mcp_obj);
285         if (mc_fd < 0) {
286                 FSLMC_VFIO_LOG(ERR, "error in VFIO get dev %s fd from group %d",
287                                mcp_obj, group->fd);
288                 return v_addr;
289         }
290
291         /* getting device info*/
292         ret = ioctl(mc_fd, VFIO_DEVICE_GET_INFO, &d_info);
293         if (ret < 0) {
294                 FSLMC_VFIO_LOG(ERR, "error in VFIO getting DEVICE_INFO");
295                 goto MC_FAILURE;
296         }
297
298         /* getting device region info*/
299         ret = ioctl(mc_fd, VFIO_DEVICE_GET_REGION_INFO, &reg_info);
300         if (ret < 0) {
301                 FSLMC_VFIO_LOG(ERR, "error in VFIO getting REGION_INFO");
302                 goto MC_FAILURE;
303         }
304
305         FSLMC_VFIO_LOG(DEBUG, "region offset = %llx  , region size = %llx",
306                        reg_info.offset, reg_info.size);
307
308         v_addr = (uint64_t)mmap(NULL, reg_info.size,
309                 PROT_WRITE | PROT_READ, MAP_SHARED,
310                 mc_fd, reg_info.offset);
311
312 MC_FAILURE:
313         close(mc_fd);
314
315         return v_addr;
316 }
317
318 static inline int
319 dpaa2_compare_dpaa2_dev(const struct rte_dpaa2_device *dev,
320                          const struct rte_dpaa2_device *dev2)
321 {
322         /*not the same family device */
323         if (dev->dev_type != DPAA2_MC_DPNI_DEVID ||
324                         dev->dev_type != DPAA2_MC_DPSECI_DEVID)
325                 return -1;
326
327         if (dev->object_id == dev2->object_id)
328                 return 0;
329         else
330                 return 1;
331 }
332
333 static void
334 fslmc_bus_add_device(struct rte_dpaa2_device *dev)
335 {
336         struct rte_fslmc_device_list *dev_l;
337
338         dev_l = &rte_fslmc_bus.device_list;
339
340         /* device is valid, add in list (sorted) */
341         if (TAILQ_EMPTY(dev_l)) {
342                 TAILQ_INSERT_TAIL(dev_l, dev, next);
343         } else {
344                 struct rte_dpaa2_device *dev2;
345                 int ret;
346
347                 TAILQ_FOREACH(dev2, dev_l, next) {
348                         ret = dpaa2_compare_dpaa2_dev(dev, dev2);
349                         if (ret <= 0)
350                                 continue;
351
352                         TAILQ_INSERT_BEFORE(dev2, dev, next);
353                         return;
354                 }
355
356                 TAILQ_INSERT_TAIL(dev_l, dev, next);
357         }
358 }
359
360 /* Following function shall fetch total available list of MC devices
361  * from VFIO container & populate private list of devices and other
362  * data structures
363  */
364 int fslmc_vfio_process_group(void)
365 {
366         struct fslmc_vfio_device *vdev;
367         struct vfio_device_info device_info = { .argsz = sizeof(device_info) };
368         char *temp_obj, *object_type, *mcp_obj, *dev_name;
369         int32_t object_id, i, dev_fd, ret;
370         DIR *d;
371         struct dirent *dir;
372         char path[PATH_MAX];
373         int64_t v_addr;
374         int ndev_count;
375         int dpio_count = 0, dpbp_count = 0;
376         struct fslmc_vfio_group *group = &vfio_groups[0];
377         static int process_once;
378
379         /* if already done once */
380         if (process_once) {
381                 FSLMC_VFIO_LOG(DEBUG,
382                                "Already scanned once - re-scan not supported");
383                 return 0;
384         }
385         process_once = 0;
386
387         sprintf(path, "/sys/kernel/iommu_groups/%d/devices", group->groupid);
388
389         d = opendir(path);
390         if (!d) {
391                 FSLMC_VFIO_LOG(ERR, "Unable to open directory %s", path);
392                 return -1;
393         }
394
395         /*Counting the number of devices in a group and getting the mcp ID*/
396         ndev_count = 0;
397         mcp_obj = NULL;
398         while ((dir = readdir(d)) != NULL) {
399                 if (dir->d_type == DT_LNK) {
400                         ndev_count++;
401                         if (!strncmp("dpmcp", dir->d_name, 5)) {
402                                 if (mcp_obj)
403                                         free(mcp_obj);
404                                 mcp_obj = malloc(sizeof(dir->d_name));
405                                 if (!mcp_obj) {
406                                         FSLMC_VFIO_LOG(ERR,
407                                                        "mcp obj:alloc failed");
408                                         closedir(d);
409                                         return -ENOMEM;
410                                 }
411                                 strcpy(mcp_obj, dir->d_name);
412                                 temp_obj = strtok(dir->d_name, ".");
413                                 temp_obj = strtok(NULL, ".");
414                                 sscanf(temp_obj, "%d", &mcp_id);
415                         }
416                 }
417         }
418         closedir(d);
419         d = NULL;
420         if (!mcp_obj) {
421                 FSLMC_VFIO_LOG(ERR, "DPAA2 MCP Object not Found");
422                 return -ENODEV;
423         }
424         RTE_LOG(INFO, EAL, "fslmc: DPRC contains = %d devices\n", ndev_count);
425
426         /* Allocate the memory depends upon number of objects in a group*/
427         group->vfio_device = (struct fslmc_vfio_device *)malloc(ndev_count *
428                              sizeof(struct fslmc_vfio_device));
429         if (!(group->vfio_device)) {
430                 FSLMC_VFIO_LOG(ERR, "vfio device: Unable to allocate memory\n");
431                 free(mcp_obj);
432                 return -ENOMEM;
433         }
434
435         /* Allocate memory for MC Portal list */
436         rte_mcp_ptr_list = malloc(sizeof(void *) * 1);
437         if (!rte_mcp_ptr_list) {
438                 FSLMC_VFIO_LOG(ERR, "portal list: Unable to allocate memory!");
439                 free(mcp_obj);
440                 goto FAILURE;
441         }
442
443         v_addr = vfio_map_mcp_obj(group, mcp_obj);
444         free(mcp_obj);
445         if (v_addr == (int64_t)MAP_FAILED) {
446                 FSLMC_VFIO_LOG(ERR, "Error mapping region (errno = %d)", errno);
447                 goto FAILURE;
448         }
449
450         rte_mcp_ptr_list[0] = (void *)v_addr;
451
452         d = opendir(path);
453         if (!d) {
454                 FSLMC_VFIO_LOG(ERR, "Unable to open %s Directory", path);
455                 goto FAILURE;
456         }
457
458         i = 0;
459         /* Parsing each object and initiating them*/
460         while ((dir = readdir(d)) != NULL) {
461                 if (dir->d_type != DT_LNK)
462                         continue;
463                 if (!strncmp("dprc", dir->d_name, 4) ||
464                     !strncmp("dpmcp", dir->d_name, 5))
465                         continue;
466                 dev_name = malloc(sizeof(dir->d_name));
467                 if (!dev_name) {
468                         FSLMC_VFIO_LOG(ERR, "name: Unable to allocate memory");
469                         goto FAILURE;
470                 }
471                 strcpy(dev_name, dir->d_name);
472                 object_type = strtok(dir->d_name, ".");
473                 temp_obj = strtok(NULL, ".");
474                 sscanf(temp_obj, "%d", &object_id);
475
476                 /* getting the device fd*/
477                 dev_fd = ioctl(group->fd, VFIO_GROUP_GET_DEVICE_FD, dev_name);
478                 if (dev_fd < 0) {
479                         FSLMC_VFIO_LOG(ERR,
480                                        "GET_DEVICE_FD error fd: %s, Group: %d",
481                                        dev_name, group->fd);
482                         free(dev_name);
483                         goto FAILURE;
484                 }
485
486                 free(dev_name);
487                 vdev = &group->vfio_device[group->object_index++];
488                 vdev->fd = dev_fd;
489                 vdev->index = i;
490                 i++;
491                 /* Get Device inofrmation */
492                 if (ioctl(vdev->fd, VFIO_DEVICE_GET_INFO, &device_info)) {
493                         FSLMC_VFIO_LOG(ERR, "DPAA2 VFIO_DEVICE_GET_INFO fail");
494                         goto FAILURE;
495                 }
496                 if (!strcmp(object_type, "dpni") ||
497                     !strcmp(object_type, "dpseci")) {
498                         struct rte_dpaa2_device *dev;
499
500                         dev = malloc(sizeof(struct rte_dpaa2_device));
501                         if (dev == NULL)
502                                 return -1;
503
504                         memset(dev, 0, sizeof(*dev));
505                         /* store hw_id of dpni/dpseci device */
506                         dev->object_id = object_id;
507                         dev->dev_type = (strcmp(object_type, "dpseci")) ?
508                                 DPAA2_MC_DPNI_DEVID : DPAA2_MC_DPSECI_DEVID;
509
510                         FSLMC_VFIO_LOG(DEBUG, "DPAA2: Added [%s-%d]",
511                                       object_type, object_id);
512
513                         fslmc_bus_add_device(dev);
514                 }
515                 if (!strcmp(object_type, "dpio")) {
516                         ret = dpaa2_create_dpio_device(vdev,
517                                                        &device_info,
518                                                        object_id);
519                         if (!ret)
520                                 dpio_count++;
521                 }
522                 if (!strcmp(object_type, "dpbp")) {
523                         ret = dpaa2_create_dpbp_device(object_id);
524                         if (!ret)
525                                 dpbp_count++;
526                 }
527         }
528         closedir(d);
529
530         ret = dpaa2_affine_qbman_swp();
531         if (ret)
532                 FSLMC_VFIO_LOG(DEBUG, "Error in affining qbman swp %d", ret);
533
534         FSLMC_VFIO_LOG(DEBUG, "DPAA2: Added dpbp_count = %d dpio_count=%d",
535                       dpbp_count, dpio_count);
536         return 0;
537
538 FAILURE:
539         if (d)
540                 closedir(d);
541         if (rte_mcp_ptr_list) {
542                 free(rte_mcp_ptr_list);
543                 rte_mcp_ptr_list = NULL;
544         }
545
546         free(group->vfio_device);
547         group->vfio_device = NULL;
548         return -1;
549 }
550
551 int fslmc_vfio_setup_group(void)
552 {
553         struct fslmc_vfio_group *group = NULL;
554         int groupid;
555         int ret, i;
556         char *container;
557         struct vfio_group_status status = { .argsz = sizeof(status) };
558
559         /* if already done once */
560         if (container_device_fd)
561                 return 0;
562
563         container = getenv("DPRC");
564
565         if (container == NULL) {
566                 FSLMC_VFIO_LOG(ERR, "VFIO container not set in env DPRC");
567                 return -EOPNOTSUPP;
568         }
569
570         /* get group number */
571         ret = vfio_get_group_no(SYSFS_FSL_MC_DEVICES, container, &groupid);
572         if (ret == 0) {
573                 RTE_LOG(WARNING, EAL, "%s not managed by VFIO, skipping\n",
574                         container);
575                 return -EOPNOTSUPP;
576         }
577
578         /* if negative, something failed */
579         if (ret < 0)
580                 return ret;
581
582         FSLMC_VFIO_LOG(DEBUG, "VFIO iommu group id = %d", groupid);
583
584         /* Check if group already exists */
585         for (i = 0; i < VFIO_MAX_GRP; i++) {
586                 group = &vfio_groups[i];
587                 if (group->groupid == groupid) {
588                         FSLMC_VFIO_LOG(ERR, "groupid already exists %d",
589                                        groupid);
590                         return 0;
591                 }
592         }
593
594         /* get the actual group fd */
595         ret = vfio_get_group_fd(groupid);
596         if (ret < 0)
597                 return ret;
598         group->fd = ret;
599
600         /*
601          * at this point, we know that this group is viable (meaning,
602          * all devices are either bound to VFIO or not bound to anything)
603          */
604
605         ret = ioctl(group->fd, VFIO_GROUP_GET_STATUS, &status);
606         if (ret) {
607                 FSLMC_VFIO_LOG(ERR, " VFIO error getting group status");
608                 close(group->fd);
609                 return ret;
610         }
611
612         if (!(status.flags & VFIO_GROUP_FLAGS_VIABLE)) {
613                 FSLMC_VFIO_LOG(ERR, "VFIO group not viable");
614                 close(group->fd);
615                 return -EPERM;
616         }
617         /* Since Group is VIABLE, Store the groupid */
618         group->groupid = groupid;
619
620         /* check if group does not have a container yet */
621         if (!(status.flags & VFIO_GROUP_FLAGS_CONTAINER_SET)) {
622                 /* Now connect this IOMMU group to given container */
623                 ret = vfio_connect_container(group);
624                 if (ret) {
625                         FSLMC_VFIO_LOG(ERR, "VFIO error connecting container"
626                                        " with groupid %d", groupid);
627                         close(group->fd);
628                         return ret;
629                 }
630         }
631
632         /* Get Device information */
633         ret = ioctl(group->fd, VFIO_GROUP_GET_DEVICE_FD, container);
634         if (ret < 0) {
635                 FSLMC_VFIO_LOG(ERR, "VFIO error getting device %s fd from"
636                                " group  %d", container, group->groupid);
637                 return ret;
638         }
639         container_device_fd = ret;
640         FSLMC_VFIO_LOG(DEBUG, "VFIO Container FD is [0x%X]",
641                      container_device_fd);
642
643         return 0;
644 }