[PATCH 5/5] net/virtio-user: support vDPA configuration callback
skoteshwar at marvell.com
skoteshwar at marvell.com
Mon Oct 7 17:04:03 CEST 2024
From: Satha Rao <skoteshwar at marvell.com>
Extended the vhost_vdpa_get_intr_fd API to create an event and
register for configuration callbacks with the vDPA backend. This
enhancement allows the virtio-user driver to handle configuration
changes more effectively.
Signed-off-by: Satha Rao <skoteshwar at marvell.com>
---
drivers/net/virtio/virtio_user/vhost_vdpa.c | 18 ++++++++++--
.../net/virtio/virtio_user/virtio_user_dev.c | 29 +++++++++++++++++++
.../net/virtio/virtio_user/virtio_user_dev.h | 2 ++
3 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/drivers/net/virtio/virtio_user/vhost_vdpa.c b/drivers/net/virtio/virtio_user/vhost_vdpa.c
index e8aea54000..c9eaffce16 100644
--- a/drivers/net/virtio/virtio_user/vhost_vdpa.c
+++ b/drivers/net/virtio/virtio_user/vhost_vdpa.c
@@ -9,6 +9,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/eventfd.h>
#include <rte_memory.h>
@@ -634,10 +635,21 @@ vhost_vdpa_update_link_state(struct virtio_user_dev *dev)
}
static int
-vhost_vdpa_get_intr_fd(struct virtio_user_dev *dev __rte_unused)
+vhost_vdpa_get_intr_fd(struct virtio_user_dev *dev)
{
- /* No link state interrupt with Vhost-vDPA */
- return -1;
+ int fd;
+
+ if (dev->cfg_epfd)
+ return dev->cfg_epfd;
+
+ fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
+ if (fd < 0) {
+ PMD_DRV_LOG(ERR, "failed to create fd error, %s", strerror(errno));
+ fd = -1;
+ }
+ dev->cfg_epfd = fd;
+
+ return fd;
}
static int
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 91ad1312f7..ea00eb50f5 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -487,6 +487,21 @@ virtio_user_dev_get_speed_duplex_config(struct virtio_user_dev *dev, void *dst,
return ret;
}
+int
+virtio_user_dev_set_config_call(struct virtio_user_dev *dev, int fd)
+{
+ int ret = 0;
+
+ if (!dev->ops->set_config_call)
+ return -ENOTSUP;
+
+ ret = dev->ops->set_config_call(dev, fd);
+ if (ret)
+ PMD_DRV_LOG(ERR, "(%s) Failed to set config call in device", dev->path);
+
+ return ret;
+}
+
static int
virtio_user_dev_init_notify(struct virtio_user_dev *dev)
{
@@ -769,6 +784,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
dev->unsupported_features = 0;
dev->backend_type = backend_type;
dev->ifname = *ifname;
+ dev->cfg_epfd = 0;
if (virtio_user_dev_setup(dev) < 0) {
PMD_INIT_LOG(ERR, "(%s) backend set up fails", dev->path);
@@ -863,6 +879,15 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
}
}
+ /* vhost vdpa register valid fd to handle config callback */
+ if (dev->cfg_epfd) {
+ struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->hw.port_id];
+
+ if (rte_intr_efd_counter_size_set(eth_dev->intr_handle, 8))
+ return -rte_errno;
+ virtio_user_dev_set_config_call(dev, dev->cfg_epfd);
+ }
+
*ifname = NULL;
return 0;
@@ -892,6 +917,10 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev)
virtio_user_free_vrings(dev);
+ if (dev->cfg_epfd) {
+ close(dev->cfg_epfd);
+ dev->cfg_epfd = 0;
+ }
free(dev->ifname);
if (dev->is_server)
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h
index 57d75d1c53..1ad93521e3 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
@@ -31,6 +31,7 @@ struct virtio_user_dev {
int *callfds;
int *kickfds;
+ int cfg_epfd; /* config callback interrupt */
int mac_specified;
uint16_t max_queue_pairs;
uint16_t queue_pairs;
@@ -89,6 +90,7 @@ int virtio_user_dev_get_rss_config(struct virtio_user_dev *dev, void *dst, size_
int length);
int virtio_user_dev_get_speed_duplex_config(struct virtio_user_dev *dev, void *dst,
size_t offset, int length);
+int virtio_user_dev_set_config_call(struct virtio_user_dev *dev, int fd);
void virtio_user_dev_delayed_disconnect_handler(void *param);
int virtio_user_dev_server_reconnect(struct virtio_user_dev *dev);
extern const char * const virtio_user_backend_strings[];
--
2.25.1
More information about the dev
mailing list