+
+int
+rte_vdpa_get_queue_num(struct rte_vdpa_device *dev, uint32_t *queue_num)
+{
+ if (dev == NULL || dev->ops == NULL || dev->ops->get_queue_num == NULL)
+ return -1;
+
+ return dev->ops->get_queue_num(dev, queue_num);
+}
+
+int
+rte_vdpa_get_features(struct rte_vdpa_device *dev, uint64_t *features)
+{
+ if (dev == NULL || dev->ops == NULL || dev->ops->get_features == NULL)
+ return -1;
+
+ return dev->ops->get_features(dev, features);
+}
+
+int
+rte_vdpa_get_protocol_features(struct rte_vdpa_device *dev, uint64_t *features)
+{
+ if (dev == NULL || dev->ops == NULL ||
+ dev->ops->get_protocol_features == NULL)
+ return -1;
+
+ return dev->ops->get_protocol_features(dev, features);
+}
+
+int
+rte_vdpa_get_stats_names(struct rte_vdpa_device *dev,
+ struct rte_vdpa_stat_name *stats_names,
+ unsigned int size)
+{
+ if (!dev)
+ return -EINVAL;
+
+ RTE_FUNC_PTR_OR_ERR_RET(dev->ops->get_stats_names, -ENOTSUP);
+
+ return dev->ops->get_stats_names(dev, stats_names, size);
+}
+
+int
+rte_vdpa_get_stats(struct rte_vdpa_device *dev, uint16_t qid,
+ struct rte_vdpa_stat *stats, unsigned int n)
+{
+ if (!dev || !stats || !n)
+ return -EINVAL;
+
+ RTE_FUNC_PTR_OR_ERR_RET(dev->ops->get_stats, -ENOTSUP);
+
+ return dev->ops->get_stats(dev, qid, stats, n);
+}
+
+int
+rte_vdpa_reset_stats(struct rte_vdpa_device *dev, uint16_t qid)
+{
+ if (!dev)
+ return -EINVAL;
+
+ RTE_FUNC_PTR_OR_ERR_RET(dev->ops->reset_stats, -ENOTSUP);
+
+ return dev->ops->reset_stats(dev, qid);
+}
+
+static int
+vdpa_dev_match(struct rte_vdpa_device *dev,
+ const struct rte_device *rte_dev)
+{
+ if (dev->device == rte_dev)
+ return 0;
+
+ return -1;
+}
+
+/* Generic rte_vdpa_dev comparison function. */
+typedef int (*rte_vdpa_cmp_t)(struct rte_vdpa_device *,
+ const struct rte_device *rte_dev);
+
+static struct rte_vdpa_device *
+vdpa_find_device(const struct rte_vdpa_device *start, rte_vdpa_cmp_t cmp,
+ struct rte_device *rte_dev)
+{
+ struct rte_vdpa_device *dev;
+
+ rte_spinlock_lock(&vdpa_device_list_lock);
+ if (start == NULL)
+ dev = TAILQ_FIRST(&vdpa_device_list);
+ else
+ dev = TAILQ_NEXT(start, next);
+
+ while (dev != NULL) {
+ if (cmp(dev, rte_dev) == 0)
+ break;
+
+ dev = TAILQ_NEXT(dev, next);
+ }
+ rte_spinlock_unlock(&vdpa_device_list_lock);
+
+ return dev;
+}
+
+static void *
+vdpa_dev_iterate(const void *start,
+ const char *str,
+ const struct rte_dev_iterator *it)
+{
+ struct rte_vdpa_device *vdpa_dev = NULL;
+
+ RTE_SET_USED(str);
+
+ vdpa_dev = vdpa_find_device(start, vdpa_dev_match, it->device);
+
+ return vdpa_dev;
+}
+
+static struct rte_class rte_class_vdpa = {
+ .dev_iterate = vdpa_dev_iterate,
+};
+
+RTE_REGISTER_CLASS(vdpa, rte_class_vdpa);