#include <rte_bus_pci.h>
#include <rte_vhost.h>
#include <rte_vdpa.h>
+#include <rte_vdpa_dev.h>
#include <rte_vfio.h>
#include <rte_spinlock.h>
#include <rte_log.h>
#include "base/ifcvf.h"
+RTE_LOG_REGISTER(ifcvf_vdpa_logtype, pmd.net.ifcvf_vdpa, NOTICE);
#define DRV_LOG(level, fmt, args...) \
rte_log(RTE_LOG_ ## level, ifcvf_vdpa_logtype, \
"IFCVF %s(): " fmt "\n", __func__, ##args)
NULL
};
-static int ifcvf_vdpa_logtype;
-
struct ifcvf_internal {
struct rte_pci_device *pdev;
struct ifcvf_hw hw;
pthread_t tid; /* thread for notify relay */
int epfd;
int vid;
- int did;
+ struct rte_vdpa_device *vdev;
uint16_t max_queues;
uint64_t features;
rte_atomic32_t started;
static void update_used_ring(struct ifcvf_internal *internal, uint16_t qid);
static struct internal_list *
-find_internal_resource_by_did(int did)
+find_internal_resource_by_vdev(struct rte_vdpa_device *vdev)
{
int found = 0;
struct internal_list *list;
pthread_mutex_lock(&internal_list_lock);
TAILQ_FOREACH(list, &internal_list, next) {
- if (did == list->internal->did) {
+ if (vdev == list->internal->vdev) {
found = 1;
break;
}
vdpa_ifcvf_stop(internal);
vdpa_disable_vfio_intr(internal);
- ret = rte_vhost_host_notifier_ctrl(vid, false);
+ ret = rte_vhost_host_notifier_ctrl(vid, RTE_VHOST_QUEUE_ALL, false);
if (ret && ret != -ENOTSUP)
goto error;
if (ret)
goto stop_vf;
- rte_vhost_host_notifier_ctrl(vid, true);
+ rte_vhost_host_notifier_ctrl(vid, RTE_VHOST_QUEUE_ALL, true);
internal->sw_fallback_running = true;
static int
ifcvf_dev_config(int vid)
{
- int did;
+ struct rte_vdpa_device *vdev;
struct internal_list *list;
struct ifcvf_internal *internal;
- did = rte_vhost_get_vdpa_device_id(vid);
- list = find_internal_resource_by_did(did);
+ vdev = rte_vhost_get_vdpa_device(vid);
+ list = find_internal_resource_by_vdev(vdev);
if (list == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
return -1;
}
rte_atomic32_set(&internal->dev_attached, 1);
update_datapath(internal);
- if (rte_vhost_host_notifier_ctrl(vid, true) != 0)
- DRV_LOG(NOTICE, "vDPA (%d): software relay is used.", did);
+ if (rte_vhost_host_notifier_ctrl(vid, RTE_VHOST_QUEUE_ALL, true) != 0)
+ DRV_LOG(NOTICE, "vDPA (%s): software relay is used.",
+ vdev->device->name);
return 0;
}
static int
ifcvf_dev_close(int vid)
{
- int did;
+ struct rte_vdpa_device *vdev;
struct internal_list *list;
struct ifcvf_internal *internal;
- did = rte_vhost_get_vdpa_device_id(vid);
- list = find_internal_resource_by_did(did);
+ vdev = rte_vhost_get_vdpa_device(vid);
+ list = find_internal_resource_by_vdev(vdev);
if (list == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
return -1;
}
ifcvf_set_features(int vid)
{
uint64_t features = 0;
- int did;
+ struct rte_vdpa_device *vdev;
struct internal_list *list;
struct ifcvf_internal *internal;
uint64_t log_base = 0, log_size = 0;
- did = rte_vhost_get_vdpa_device_id(vid);
- list = find_internal_resource_by_did(did);
+ vdev = rte_vhost_get_vdpa_device(vid);
+ list = find_internal_resource_by_vdev(vdev);
if (list == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
return -1;
}
static int
ifcvf_get_vfio_group_fd(int vid)
{
- int did;
+ struct rte_vdpa_device *vdev;
struct internal_list *list;
- did = rte_vhost_get_vdpa_device_id(vid);
- list = find_internal_resource_by_did(did);
+ vdev = rte_vhost_get_vdpa_device(vid);
+ list = find_internal_resource_by_vdev(vdev);
if (list == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
return -1;
}
static int
ifcvf_get_vfio_device_fd(int vid)
{
- int did;
+ struct rte_vdpa_device *vdev;
struct internal_list *list;
- did = rte_vhost_get_vdpa_device_id(vid);
- list = find_internal_resource_by_did(did);
+ vdev = rte_vhost_get_vdpa_device(vid);
+ list = find_internal_resource_by_vdev(vdev);
if (list == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
return -1;
}
static int
ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size)
{
- int did;
+ struct rte_vdpa_device *vdev;
struct internal_list *list;
struct ifcvf_internal *internal;
struct vfio_region_info reg = { .argsz = sizeof(reg) };
int ret;
- did = rte_vhost_get_vdpa_device_id(vid);
- list = find_internal_resource_by_did(did);
+ vdev = rte_vhost_get_vdpa_device(vid);
+ list = find_internal_resource_by_vdev(vdev);
if (list == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
return -1;
}
}
static int
-ifcvf_get_queue_num(int did, uint32_t *queue_num)
+ifcvf_get_queue_num(struct rte_vdpa_device *vdev, uint32_t *queue_num)
{
struct internal_list *list;
- list = find_internal_resource_by_did(did);
+ list = find_internal_resource_by_vdev(vdev);
if (list == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
return -1;
}
}
static int
-ifcvf_get_vdpa_features(int did, uint64_t *features)
+ifcvf_get_vdpa_features(struct rte_vdpa_device *vdev, uint64_t *features)
{
struct internal_list *list;
- list = find_internal_resource_by_did(did);
+ list = find_internal_resource_by_vdev(vdev);
if (list == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %p", vdev);
return -1;
}
1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER | \
1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD)
static int
-ifcvf_get_protocol_features(int did __rte_unused, uint64_t *features)
+ifcvf_get_protocol_features(struct rte_vdpa_device *vdev, uint64_t *features)
{
+ RTE_SET_USED(vdev);
+
*features = VDPA_SUPPORTED_PROTOCOL_FEATURES;
return 0;
}
}
internal->sw_lm = sw_fallback_lm;
- internal->did = rte_vdpa_register_device(&pci_dev->device, &ifcvf_ops);
- if (internal->did < 0) {
+ internal->vdev = rte_vdpa_register_device(&pci_dev->device, &ifcvf_ops);
+ if (internal->vdev == NULL) {
DRV_LOG(ERR, "failed to register device %s", pci_dev->name);
goto error;
}
rte_pci_unmap_device(internal->pdev);
rte_vfio_container_destroy(internal->vfio_container_fd);
- rte_vdpa_unregister_device(internal->did);
+ rte_vdpa_unregister_device(internal->vdev);
pthread_mutex_lock(&internal_list_lock);
TAILQ_REMOVE(&internal_list, list, next);
RTE_PMD_REGISTER_PCI(net_ifcvf, rte_ifcvf_vdpa);
RTE_PMD_REGISTER_PCI_TABLE(net_ifcvf, pci_id_ifcvf_map);
RTE_PMD_REGISTER_KMOD_DEP(net_ifcvf, "* vfio-pci");
-
-RTE_INIT(ifcvf_vdpa_init_log)
-{
- ifcvf_vdpa_logtype = rte_log_register("pmd.net.ifcvf_vdpa");
- if (ifcvf_vdpa_logtype >= 0)
- rte_log_set_level(ifcvf_vdpa_logtype, RTE_LOG_NOTICE);
-}