+static int
+mlx5_vdpa_get_device_fd(int vid)
+{
+ struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid);
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
+
+ if (priv == NULL) {
+ DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
+ return -EINVAL;
+ }
+ return priv->ctx->cmd_fd;
+}
+
+static int
+mlx5_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size)
+{
+ struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid);
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
+
+ RTE_SET_USED(qid);
+ if (priv == NULL) {
+ DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
+ return -EINVAL;
+ }
+ if (!priv->var) {
+ DRV_LOG(ERR, "VAR was not created for device %s, is the device"
+ " configured?.", vdev->device->name);
+ return -EINVAL;
+ }
+ *offset = priv->var->mmap_off;
+ *size = priv->var->length;
+ return 0;
+}
+
+static int
+mlx5_vdpa_get_stats_names(struct rte_vdpa_device *vdev,
+ struct rte_vdpa_stat_name *stats_names,
+ unsigned int size)
+{
+ static const char *mlx5_vdpa_stats_names[MLX5_VDPA_STATS_MAX] = {
+ "received_descriptors",
+ "completed_descriptors",
+ "bad descriptor errors",
+ "exceed max chain",
+ "invalid buffer",
+ "completion errors",
+ };
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
+ unsigned int i;
+
+ if (priv == NULL) {
+ DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name);
+ return -ENODEV;
+ }
+ if (!stats_names)
+ return MLX5_VDPA_STATS_MAX;
+ size = RTE_MIN(size, (unsigned int)MLX5_VDPA_STATS_MAX);
+ for (i = 0; i < size; ++i)
+ strlcpy(stats_names[i].name, mlx5_vdpa_stats_names[i],
+ RTE_VDPA_STATS_NAME_SIZE);
+ return size;
+}
+
+static int
+mlx5_vdpa_get_stats(struct rte_vdpa_device *vdev, int qid,
+ struct rte_vdpa_stat *stats, unsigned int n)
+{
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
+
+ if (priv == NULL) {
+ DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name);
+ return -ENODEV;
+ }
+ if (!priv->configured) {
+ DRV_LOG(ERR, "Device %s was not configured.",
+ vdev->device->name);
+ return -ENODATA;
+ }
+ if (qid >= (int)priv->nr_virtqs) {
+ DRV_LOG(ERR, "Too big vring id: %d for device %s.", qid,
+ vdev->device->name);
+ return -E2BIG;
+ }
+ if (!priv->caps.queue_counters_valid) {
+ DRV_LOG(ERR, "Virtq statistics is not supported for device %s.",
+ vdev->device->name);
+ return -ENOTSUP;
+ }
+ return mlx5_vdpa_virtq_stats_get(priv, qid, stats, n);
+}
+
+static int
+mlx5_vdpa_reset_stats(struct rte_vdpa_device *vdev, int qid)
+{
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
+
+ if (priv == NULL) {
+ DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name);
+ return -ENODEV;
+ }
+ if (!priv->configured) {
+ DRV_LOG(ERR, "Device %s was not configured.",
+ vdev->device->name);
+ return -ENODATA;
+ }
+ if (qid >= (int)priv->nr_virtqs) {
+ DRV_LOG(ERR, "Too big vring id: %d for device %s.", qid,
+ vdev->device->name);
+ return -E2BIG;
+ }
+ if (!priv->caps.queue_counters_valid) {
+ DRV_LOG(ERR, "Virtq statistics is not supported for device %s.",
+ vdev->device->name);
+ return -ENOTSUP;
+ }
+ return mlx5_vdpa_virtq_stats_reset(priv, qid);
+}
+