+
+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 uint16_t
+vdpa_dev_to_id(const struct rte_vdpa_device *dev)
+{
+ if (dev == NULL)
+ return MAX_VHOST_DEVICE;
+
+ if (dev < &vdpa_devices[0] ||
+ dev >= &vdpa_devices[MAX_VHOST_DEVICE])
+ return MAX_VHOST_DEVICE;
+
+ return (uint16_t)(dev - vdpa_devices);
+}
+
+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;
+ uint16_t idx;
+
+ if (start != NULL)
+ idx = vdpa_dev_to_id(start) + 1;
+ else
+ idx = 0;
+ for (; idx < MAX_VHOST_DEVICE; idx++) {
+ dev = &vdpa_devices[idx];
+ /*
+ * ToDo: Certainly better to introduce a state field,
+ * but rely on ops being set for now.
+ */
+ if (dev->ops == NULL)
+ continue;
+ if (cmp(dev, rte_dev) == 0)
+ return dev;
+ }
+ return NULL;
+}
+
+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);