net/bnxt: consolidate template table processing
[dpdk.git] / lib / librte_eal / linux / eal_vfio.c
index 2a1eda5..380f2f4 100644 (file)
@@ -295,7 +295,7 @@ vfio_open_group_fd(int iommu_group_num)
                                                        strerror(errno));
                                        return -1;
                                }
-                               return 0;
+                               return -ENOENT;
                        }
                        /* noiommu group found */
                }
@@ -320,12 +320,12 @@ vfio_open_group_fd(int iommu_group_num)
                        vfio_group_fd = mp_rep->fds[0];
                } else if (p->result == SOCKET_NO_FD) {
                        RTE_LOG(ERR, EAL, "  bad VFIO group fd\n");
-                       vfio_group_fd = 0;
+                       vfio_group_fd = -ENOENT;
                }
        }
 
        free(mp_reply.msgs);
-       if (vfio_group_fd < 0)
+       if (vfio_group_fd < 0 && vfio_group_fd != -ENOENT)
                RTE_LOG(ERR, EAL, "  cannot request group fd\n");
        return vfio_group_fd;
 }
@@ -381,9 +381,9 @@ vfio_get_group_fd(struct vfio_config *vfio_cfg,
        }
 
        vfio_group_fd = vfio_open_group_fd(iommu_group_num);
-       if (vfio_group_fd <= 0) {
+       if (vfio_group_fd < 0) {
                RTE_LOG(ERR, EAL, "Failed to open group %d\n", iommu_group_num);
-               return -1;
+               return vfio_group_fd;
        }
 
        cur_grp->group_num = iommu_group_num;
@@ -714,6 +714,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
        int vfio_container_fd;
        int vfio_group_fd;
        int iommu_group_num;
+       rte_uuid_t vf_token;
        int i, ret;
        const struct internal_config *internal_conf =
                eal_get_internal_configuration();
@@ -732,11 +733,14 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
 
        /* get the actual group fd */
        vfio_group_fd = rte_vfio_get_group_fd(iommu_group_num);
-       if (vfio_group_fd < 0)
+       if (vfio_group_fd < 0 && vfio_group_fd != -ENOENT)
                return -1;
 
-       /* if group_fd == 0, that means the device isn't managed by VFIO */
-       if (vfio_group_fd == 0) {
+       /*
+        * if vfio_group_fd == -ENOENT, that means the device
+        * isn't managed by VFIO
+        */
+       if (vfio_group_fd == -ENOENT) {
                RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n",
                                dev_addr);
                return 1;
@@ -899,6 +903,23 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
                                t->type_id, t->name);
        }
 
+       rte_eal_vfio_get_vf_token(vf_token);
+
+       /* get a file descriptor for the device with VF token firstly */
+       if (!rte_uuid_is_null(vf_token)) {
+               char vf_token_str[RTE_UUID_STRLEN];
+               char dev[PATH_MAX];
+
+               rte_uuid_unparse(vf_token, vf_token_str, sizeof(vf_token_str));
+               snprintf(dev, sizeof(dev),
+                        "%s vf_token=%s", dev_addr, vf_token_str);
+
+               *vfio_dev_fd = ioctl(vfio_group_fd, VFIO_GROUP_GET_DEVICE_FD,
+                                    dev);
+               if (*vfio_dev_fd >= 0)
+                       goto dev_get_info;
+       }
+
        /* get a file descriptor for the device */
        *vfio_dev_fd = ioctl(vfio_group_fd, VFIO_GROUP_GET_DEVICE_FD, dev_addr);
        if (*vfio_dev_fd < 0) {
@@ -914,6 +935,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
        }
 
        /* test and setup the device */
+dev_get_info:
        ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
        if (ret) {
                RTE_LOG(ERR, EAL, "  %s cannot get device info, "
@@ -956,10 +978,10 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr,
 
        /* get the actual group fd */
        vfio_group_fd = rte_vfio_get_group_fd(iommu_group_num);
-       if (vfio_group_fd <= 0) {
+       if (vfio_group_fd < 0) {
                RTE_LOG(INFO, EAL, "rte_vfio_get_group_fd failed for %s\n",
                                   dev_addr);
-               ret = -1;
+               ret = vfio_group_fd;
                goto out;
        }