X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_eal%2Flinux%2Feal_vfio.c;h=e07979936edbeb8743569ced7dbc35506d7b8d02;hb=0f9ac2afa62ebacd24f36a3b98272b7146be3edd;hp=4502aefed33267fedf1695b8770597d320703c80;hpb=a083f8cc77460c15ac99a427ab6833dc8c8ae5bc;p=dpdk.git diff --git a/lib/librte_eal/linux/eal_vfio.c b/lib/librte_eal/linux/eal_vfio.c index 4502aefed3..e07979936e 100644 --- a/lib/librte_eal/linux/eal_vfio.c +++ b/lib/librte_eal/linux/eal_vfio.c @@ -267,9 +267,11 @@ vfio_open_group_fd(int iommu_group_num) struct rte_mp_reply mp_reply = {0}; struct timespec ts = {.tv_sec = 5, .tv_nsec = 0}; struct vfio_mp_param *p = (struct vfio_mp_param *)mp_req.param; + const struct internal_config *internal_conf = + eal_get_internal_configuration(); /* if primary, try to open the group */ - if (internal_config.process_type == RTE_PROC_PRIMARY) { + if (internal_conf->process_type == RTE_PROC_PRIMARY) { /* try regular group format */ snprintf(filename, sizeof(filename), VFIO_GROUP_FMT, iommu_group_num); @@ -379,7 +381,7 @@ 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; } @@ -712,7 +714,10 @@ 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(); /* get group number */ ret = rte_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_num); @@ -788,7 +793,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, * Note this can happen several times with the hotplug * functionality. */ - if (internal_config.process_type == RTE_PROC_PRIMARY && + if (internal_conf->process_type == RTE_PROC_PRIMARY && vfio_cfg->vfio_active_groups == 1 && vfio_group_device_count(vfio_group_fd) == 0) { const struct vfio_iommu_type *t; @@ -891,10 +896,27 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, /* we have successfully initialized VFIO, notify user */ const struct vfio_iommu_type *t = default_vfio_cfg->vfio_iommu_type; - RTE_LOG(NOTICE, EAL, " using IOMMU type %d (%s)\n", + RTE_LOG(INFO, EAL, " using IOMMU type %d (%s)\n", 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) { @@ -910,6 +932,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, " @@ -929,9 +952,6 @@ int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int vfio_dev_fd) { - struct vfio_group_status group_status = { - .argsz = sizeof(group_status) - }; struct vfio_config *vfio_cfg; int vfio_group_fd; int iommu_group_num; @@ -1022,6 +1042,8 @@ rte_vfio_enable(const char *modname) /* initialize group list */ int i, j; int vfio_available; + const struct internal_config *internal_conf = + eal_get_internal_configuration(); rte_spinlock_recursive_t lock = RTE_SPINLOCK_RECURSIVE_INITIALIZER; @@ -1057,7 +1079,7 @@ rte_vfio_enable(const char *modname) return 0; } - if (internal_config.process_type == RTE_PROC_PRIMARY) { + if (internal_conf->process_type == RTE_PROC_PRIMARY) { /* open a new container */ default_vfio_cfg->vfio_container_fd = rte_vfio_get_container_fd(); @@ -1069,7 +1091,7 @@ rte_vfio_enable(const char *modname) /* check if we have VFIO driver enabled */ if (default_vfio_cfg->vfio_container_fd != -1) { - RTE_LOG(NOTICE, EAL, "VFIO support initialized\n"); + RTE_LOG(INFO, EAL, "VFIO support initialized\n"); default_vfio_cfg->vfio_enabled = 1; } else { RTE_LOG(NOTICE, EAL, "VFIO support could not be initialized\n"); @@ -1092,11 +1114,14 @@ vfio_get_default_container_fd(void) struct rte_mp_reply mp_reply = {0}; struct timespec ts = {.tv_sec = 5, .tv_nsec = 0}; struct vfio_mp_param *p = (struct vfio_mp_param *)mp_req.param; + int container_fd; + const struct internal_config *internal_conf = + eal_get_internal_configuration(); if (default_vfio_cfg->vfio_enabled) return default_vfio_cfg->vfio_container_fd; - if (internal_config.process_type == RTE_PROC_PRIMARY) { + if (internal_conf->process_type == RTE_PROC_PRIMARY) { /* if we were secondary process we would try requesting * container fd from the primary, but we're the primary * process so just exit here @@ -1114,8 +1139,9 @@ vfio_get_default_container_fd(void) mp_rep = &mp_reply.msgs[0]; p = (struct vfio_mp_param *)mp_rep->param; if (p->result == SOCKET_OK && mp_rep->num_fds == 1) { + container_fd = mp_rep->fds[0]; free(mp_reply.msgs); - return mp_rep->fds[0]; + return container_fd; } } @@ -1143,7 +1169,7 @@ vfio_set_iommu_type(int vfio_container_fd) int ret = ioctl(vfio_container_fd, VFIO_SET_IOMMU, t->type_id); if (!ret) { - RTE_LOG(NOTICE, EAL, " using IOMMU type %d (%s)\n", + RTE_LOG(INFO, EAL, " using IOMMU type %d (%s)\n", t->type_id, t->name); return t; } @@ -1198,10 +1224,12 @@ rte_vfio_get_container_fd(void) struct rte_mp_reply mp_reply = {0}; struct timespec ts = {.tv_sec = 5, .tv_nsec = 0}; struct vfio_mp_param *p = (struct vfio_mp_param *)mp_req.param; + const struct internal_config *internal_conf = + eal_get_internal_configuration(); /* if we're in a primary process, try to open the container */ - if (internal_config.process_type == RTE_PROC_PRIMARY) { + if (internal_conf->process_type == RTE_PROC_PRIMARY) { vfio_container_fd = open(VFIO_CONTAINER_PATH, O_RDWR); if (vfio_container_fd < 0) { RTE_LOG(ERR, EAL, " cannot open VFIO container, "