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;
}
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_vdpa_get_device(rte_vhost_get_vdpa_device_id(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;
}
update_datapath(internal);
if (rte_vhost_host_notifier_ctrl(vid, true) != 0)
- DRV_LOG(NOTICE, "vDPA (%d): software relay is used.", did);
+ 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_vdpa_get_device(rte_vhost_get_vdpa_device_id(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_vdpa_get_device(rte_vhost_get_vdpa_device_id(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_vdpa_get_device(rte_vhost_get_vdpa_device_id(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_vdpa_get_device(rte_vhost_get_vdpa_device_id(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_vdpa_get_device(rte_vhost_get_vdpa_device_id(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);
int mlx5_vdpa_logtype;
static struct mlx5_vdpa_priv *
-mlx5_vdpa_find_priv_resource_by_did(int did)
+mlx5_vdpa_find_priv_resource_by_vdev(struct rte_vdpa_device *vdev)
{
struct mlx5_vdpa_priv *priv;
int found = 0;
pthread_mutex_lock(&priv_list_lock);
TAILQ_FOREACH(priv, &priv_list, next) {
- if (did == priv->id) {
+ if (vdev == priv->vdev) {
found = 1;
break;
}
}
pthread_mutex_unlock(&priv_list_lock);
if (!found) {
- DRV_LOG(ERR, "Invalid device id: %d.", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
rte_errno = EINVAL;
return NULL;
}
}
static int
-mlx5_vdpa_get_queue_num(int did, uint32_t *queue_num)
+mlx5_vdpa_get_queue_num(struct rte_vdpa_device *vdev, uint32_t *queue_num)
{
- struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
if (priv == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d.", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
return -1;
}
*queue_num = priv->caps.max_num_virtio_queues;
}
static int
-mlx5_vdpa_get_vdpa_features(int did, uint64_t *features)
+mlx5_vdpa_get_vdpa_features(struct rte_vdpa_device *vdev, uint64_t *features)
{
- struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
if (priv == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d.", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
return -1;
}
*features = MLX5_VDPA_DEFAULT_FEATURES;
}
static int
-mlx5_vdpa_get_protocol_features(int did, uint64_t *features)
+mlx5_vdpa_get_protocol_features(struct rte_vdpa_device *vdev,
+ uint64_t *features)
{
- struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
if (priv == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d.", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
return -1;
}
*features = MLX5_VDPA_PROTOCOL_FEATURES;
static int
mlx5_vdpa_set_vring_state(int vid, int vring, int state)
{
- int did = rte_vhost_get_vdpa_device_id(vid);
- struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+ struct rte_vdpa_device *vdev = rte_vdpa_get_device(
+ rte_vhost_get_vdpa_device_id(vid));
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
if (priv == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d.", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
return -EINVAL;
}
if (vring >= (int)priv->caps.max_num_virtio_queues * 2) {
static int
mlx5_vdpa_features_set(int vid)
{
- int did = rte_vhost_get_vdpa_device_id(vid);
- struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+ struct rte_vdpa_device *vdev = rte_vdpa_get_device(
+ rte_vhost_get_vdpa_device_id(vid));
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
uint64_t log_base, log_size;
uint64_t features;
int ret;
if (priv == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d.", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
return -EINVAL;
}
ret = rte_vhost_get_negotiated_features(vid, &features);
static int
mlx5_vdpa_dev_close(int vid)
{
- int did = rte_vhost_get_vdpa_device_id(vid);
- struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+ struct rte_vdpa_device *vdev = rte_vdpa_get_device(
+ rte_vhost_get_vdpa_device_id(vid));
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
int ret = 0;
if (priv == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d.", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
return -1;
}
if (priv->configured)
static int
mlx5_vdpa_dev_config(int vid)
{
- int did = rte_vhost_get_vdpa_device_id(vid);
- struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+ struct rte_vdpa_device *vdev = rte_vdpa_get_device(
+ rte_vhost_get_vdpa_device_id(vid));
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
if (priv == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d.", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
return -EINVAL;
}
if (priv->configured && mlx5_vdpa_dev_close(vid)) {
}
priv->vid = vid;
if (mlx5_vdpa_mtu_set(priv))
- DRV_LOG(WARNING, "MTU cannot be set on device %d.", did);
+ DRV_LOG(WARNING, "MTU cannot be set on device %s.",
+ vdev->device->name);
if (mlx5_vdpa_pd_create(priv) || mlx5_vdpa_mem_register(priv) ||
mlx5_vdpa_direct_db_prepare(priv) ||
mlx5_vdpa_virtqs_prepare(priv) || mlx5_vdpa_steer_setup(priv) ||
static int
mlx5_vdpa_get_device_fd(int vid)
{
- int did = rte_vhost_get_vdpa_device_id(vid);
- struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+ struct rte_vdpa_device *vdev = rte_vdpa_get_device(
+ rte_vhost_get_vdpa_device_id(vid));
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
if (priv == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d.", did);
+ 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)
{
- int did = rte_vhost_get_vdpa_device_id(vid);
- struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+ struct rte_vdpa_device *vdev = rte_vdpa_get_device(
+ rte_vhost_get_vdpa_device_id(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 device id: %d.", did);
+ DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
return -EINVAL;
}
if (!priv->var) {
- DRV_LOG(ERR, "VAR was not created for device %d, is the device"
- " configured?.", did);
+ DRV_LOG(ERR, "VAR was not created for device %s, is the device"
+ " configured?.", vdev->device->name);
return -EINVAL;
}
*offset = priv->var->mmap_off;
}
static int
-mlx5_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names,
- unsigned int size)
+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",
"invalid buffer",
"completion errors",
};
- struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
unsigned int i;
if (priv == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d.", did);
+ DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name);
return -ENODEV;
}
if (!stats_names)
}
static int
-mlx5_vdpa_get_stats(int did, int qid, struct rte_vdpa_stat *stats,
- unsigned int n)
+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_did(did);
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
if (priv == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d.", did);
+ DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name);
return -ENODEV;
}
if (!priv->configured) {
- DRV_LOG(ERR, "Device %d was not configured.", did);
+ 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.", qid);
+ 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 %d.",
- did);
+ 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(int did, int qid)
+mlx5_vdpa_reset_stats(struct rte_vdpa_device *vdev, int qid)
{
- struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+ struct mlx5_vdpa_priv *priv =
+ mlx5_vdpa_find_priv_resource_by_vdev(vdev);
if (priv == NULL) {
- DRV_LOG(ERR, "Invalid device id: %d.", did);
+ DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name);
return -ENODEV;
}
if (!priv->configured) {
- DRV_LOG(ERR, "Device %d was not configured.", did);
+ 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.", qid);
+ 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 %d.",
- did);
+ DRV_LOG(ERR, "Virtq statistics is not supported for device %s.",
+ vdev->device->name);
return -ENOTSUP;
}
return mlx5_vdpa_virtq_stats_reset(priv, qid);
DRV_LOG(ERR, "Failed to allocate VAR %u.\n", errno);
goto error;
}
- priv->id = rte_vdpa_register_device(&pci_dev->device, &mlx5_vdpa_ops);
- if (priv->id < 0) {
+ priv->vdev = rte_vdpa_register_device(&pci_dev->device,
+ &mlx5_vdpa_ops);
+ if (priv->vdev == NULL) {
DRV_LOG(ERR, "Failed to register vDPA device.");
rte_errno = rte_errno ? rte_errno : EINVAL;
goto error;
TAILQ_ENTRY(mlx5_vdpa_priv) next;
uint8_t configured;
uint8_t direct_notifier; /* Whether direct notifier is on or off. */
- int id; /* vDPA device id. */
+ struct rte_vdpa_device *vdev; /* vDPA device. */
int vid; /* vhost device id. */
struct ibv_context *ctx; /* Device context. */
struct rte_pci_device *pci_dev;
vdev = rte_vdpa_get_device(did);
if (!vdev)
continue;
- if (vdev->ops->get_queue_num(did, &queue_num) < 0) {
+ if (vdev->ops->get_queue_num(vdev, &queue_num) < 0) {
RTE_LOG(ERR, VDPA,
"failed to get vdpa queue number "
"for device id %d.\n", did);
continue;
}
- if (vdev->ops->get_features(did, &features) < 0) {
+ if (vdev->ops->get_features(vdev, &features) < 0) {
RTE_LOG(ERR, VDPA,
"failed to get vdpa features "
"for device id %d.\n", did);
/** Maximum name length for statistics counters */
#define RTE_VDPA_STATS_NAME_SIZE 64
+struct rte_vdpa_device;
+
/**
* A vDPA device statistic structure
*
*/
struct rte_vdpa_dev_ops {
/** Get capabilities of this device */
- int (*get_queue_num)(int did, uint32_t *queue_num);
+ int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num);
/** Get supported features of this device */
- int (*get_features)(int did, uint64_t *features);
+ int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features);
/** Get supported protocol features of this device */
- int (*get_protocol_features)(int did, uint64_t *protocol_features);
+ int (*get_protocol_features)(struct rte_vdpa_device *dev,
+ uint64_t *protocol_features);
/** Driver configure/close the device */
int (*dev_conf)(int vid);
uint64_t *offset, uint64_t *size);
/** Get statistics name */
- int (*get_stats_names)(int did, struct rte_vdpa_stat_name *stats_names,
- unsigned int size);
+ int (*get_stats_names)(struct rte_vdpa_device *dev,
+ struct rte_vdpa_stat_name *stats_names,
+ unsigned int size);
/** Get statistics of the queue */
- int (*get_stats)(int did, int qid, struct rte_vdpa_stat *stats,
- unsigned int n);
+ int (*get_stats)(struct rte_vdpa_device *dev, int qid,
+ struct rte_vdpa_stat *stats, unsigned int n);
/** Reset statistics of the queue */
- int (*reset_stats)(int did, int qid);
+ int (*reset_stats)(struct rte_vdpa_device *dev, int qid);
/** Reserved for future extension */
void *reserved[2];
* @param ops
* the vdpa device operations
* @return
- * device id on success, -1 on failure
+ * vDPA device pointer on success, NULL on failure
*/
__rte_experimental
-int
+struct rte_vdpa_device *
rte_vdpa_register_device(struct rte_device *rte_dev,
struct rte_vdpa_dev_ops *ops);
* Unregister a vdpa device
*
* @param did
- * vdpa device id
+ * vDPA device pointer
* @return
* device id on success, -1 on failure
*/
__rte_experimental
int
-rte_vdpa_unregister_device(int did);
+rte_vdpa_unregister_device(struct rte_vdpa_device *);
/**
* @warning
goto unlock_exit;
}
- if (vdpa_dev->ops->get_features(did, &vdpa_features) < 0) {
+ if (vdpa_dev->ops->get_features(vdpa_dev, &vdpa_features) < 0) {
VHOST_LOG_CONFIG(ERR,
"failed to get vdpa features "
"for socket file %s.\n", path);
goto unlock_exit;
}
- if (vdpa_dev->ops->get_protocol_features(did,
+ if (vdpa_dev->ops->get_protocol_features(vdpa_dev,
&vdpa_protocol_features) < 0) {
VHOST_LOG_CONFIG(ERR,
"failed to get vdpa protocol features "
goto unlock_exit;
}
- if (vdpa_dev->ops->get_queue_num(did, &vdpa_queue_num) < 0) {
+ if (vdpa_dev->ops->get_queue_num(vdpa_dev, &vdpa_queue_num) < 0) {
VHOST_LOG_CONFIG(ERR,
"failed to get vdpa queue number "
"for socket file %s.\n", path);
static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE];
static uint32_t vdpa_device_num;
-int
-rte_vdpa_register_device(struct rte_device *rte_dev,
- struct rte_vdpa_dev_ops *ops)
-{
- struct rte_vdpa_device *dev;
- int i;
-
- if (vdpa_device_num >= MAX_VHOST_DEVICE || ops == NULL)
- return -1;
-
- for (i = 0; i < MAX_VHOST_DEVICE; i++) {
- dev = &vdpa_devices[i];
- if (dev->ops == NULL)
- continue;
-
- if (dev->device == rte_dev)
- return -1;
- }
-
- for (i = 0; i < MAX_VHOST_DEVICE; i++) {
- if (vdpa_devices[i].ops == NULL)
- break;
- }
-
- if (i == MAX_VHOST_DEVICE)
- return -1;
-
- dev = &vdpa_devices[i];
- dev->device = rte_dev;
- dev->ops = ops;
- vdpa_device_num++;
-
- return i;
-}
-
-int
-rte_vdpa_unregister_device(int did)
-{
- if (did < 0 || did >= MAX_VHOST_DEVICE || vdpa_devices[did].ops == NULL)
- return -1;
-
- memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device));
- vdpa_device_num--;
-
- return did;
-}
int
rte_vdpa_find_device_id(struct rte_vdpa_device *dev)
return &vdpa_devices[did];
}
+struct rte_vdpa_device *
+rte_vdpa_register_device(struct rte_device *rte_dev,
+ struct rte_vdpa_dev_ops *ops)
+{
+ struct rte_vdpa_device *dev;
+ int i;
+
+ if (vdpa_device_num >= MAX_VHOST_DEVICE || ops == NULL)
+ return NULL;
+
+ for (i = 0; i < MAX_VHOST_DEVICE; i++) {
+ dev = &vdpa_devices[i];
+ if (dev->ops == NULL)
+ continue;
+
+ if (dev->device == rte_dev)
+ return NULL;
+ }
+
+ for (i = 0; i < MAX_VHOST_DEVICE; i++) {
+ if (vdpa_devices[i].ops == NULL)
+ break;
+ }
+
+ if (i == MAX_VHOST_DEVICE)
+ return NULL;
+
+ dev = &vdpa_devices[i];
+ dev->device = rte_dev;
+ dev->ops = ops;
+ vdpa_device_num++;
+
+ return dev;
+}
+
+int
+rte_vdpa_unregister_device(struct rte_vdpa_device *vdev)
+{
+ int did = rte_vdpa_find_device_id(vdev);
+
+ if (did < 0 || vdpa_devices[did].ops == NULL)
+ return -1;
+
+ memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device));
+ vdpa_device_num--;
+
+ return 0;
+}
+
int
rte_vdpa_get_device_num(void)
{
RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_stats_names, -ENOTSUP);
- return vdpa_dev->ops->get_stats_names(did, stats_names, size);
+ return vdpa_dev->ops->get_stats_names(vdpa_dev, stats_names, size);
}
int
RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_stats, -ENOTSUP);
- return vdpa_dev->ops->get_stats(did, qid, stats, n);
+ return vdpa_dev->ops->get_stats(vdpa_dev, qid, stats, n);
}
int
RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->reset_stats, -ENOTSUP);
- return vdpa_dev->ops->reset_stats(did, qid);
+ return vdpa_dev->ops->reset_stats(vdpa_dev, qid);
}
static uint16_t