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