From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, Chaoyong He <chaoyong.he@corigine.com>,
Shujing Dong <shujing.dong@corigine.com>,
Long Wu <long.wu@corigine.com>,
Peng Zhang <peng.zhang@corigine.com>
Subject: [PATCH v4 24/24] vdpa/nfp: add device operations
Date: Fri, 27 Oct 2023 11:00:01 +0800 [thread overview]
Message-ID: <20231027030001.602639-25-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20231027030001.602639-1-chaoyong.he@corigine.com>
Implement the corresponding nfp vDPA operation functions.
Signed-off-by: Shujing Dong <shujing.dong@corigine.com>
Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
drivers/vdpa/nfp/nfp_vdpa.c | 213 ++++++++++++++++++++++++++++++++++++
1 file changed, 213 insertions(+)
diff --git a/drivers/vdpa/nfp/nfp_vdpa.c b/drivers/vdpa/nfp/nfp_vdpa.c
index c104588663..a1d1dc4f73 100644
--- a/drivers/vdpa/nfp/nfp_vdpa.c
+++ b/drivers/vdpa/nfp/nfp_vdpa.c
@@ -57,6 +57,29 @@ static struct vdpa_dev_list_head vdpa_dev_list =
static pthread_mutex_t vdpa_list_lock = PTHREAD_MUTEX_INITIALIZER;
+static struct nfp_vdpa_dev_node *
+nfp_vdpa_find_node_by_vdev(struct rte_vdpa_device *vdev)
+{
+ bool found = false;
+ struct nfp_vdpa_dev_node *node;
+
+ pthread_mutex_lock(&vdpa_list_lock);
+
+ TAILQ_FOREACH(node, &vdpa_dev_list, next) {
+ if (vdev == node->device->vdev) {
+ found = true;
+ break;
+ }
+ }
+
+ pthread_mutex_unlock(&vdpa_list_lock);
+
+ if (found)
+ return node;
+
+ return NULL;
+}
+
static struct nfp_vdpa_dev_node *
nfp_vdpa_find_node_by_pdev(struct rte_pci_device *pdev)
{
@@ -578,7 +601,197 @@ update_datapath(struct nfp_vdpa_dev *device)
return ret;
}
+static int
+nfp_vdpa_dev_config(int vid)
+{
+ int ret;
+ struct nfp_vdpa_dev *device;
+ struct rte_vdpa_device *vdev;
+ struct nfp_vdpa_dev_node *node;
+
+ vdev = rte_vhost_get_vdpa_device(vid);
+ node = nfp_vdpa_find_node_by_vdev(vdev);
+ if (node == NULL) {
+ DRV_VDPA_LOG(ERR, "Invalid vDPA device: %p", vdev);
+ return -ENODEV;
+ }
+
+ device = node->device;
+ device->vid = vid;
+ rte_atomic_store_explicit(&device->dev_attached, 1, rte_memory_order_relaxed);
+ update_datapath(device);
+
+ ret = rte_vhost_host_notifier_ctrl(vid, RTE_VHOST_QUEUE_ALL, true);
+ if (ret != 0)
+ DRV_VDPA_LOG(INFO, "vDPA (%s): software relay is used.",
+ vdev->device->name);
+
+ return 0;
+}
+
+static int
+nfp_vdpa_dev_close(int vid)
+{
+ struct nfp_vdpa_dev *device;
+ struct rte_vdpa_device *vdev;
+ struct nfp_vdpa_dev_node *node;
+
+ vdev = rte_vhost_get_vdpa_device(vid);
+ node = nfp_vdpa_find_node_by_vdev(vdev);
+ if (node == NULL) {
+ DRV_VDPA_LOG(ERR, "Invalid vDPA device: %p", vdev);
+ return -ENODEV;
+ }
+
+ device = node->device;
+ rte_atomic_store_explicit(&device->dev_attached, 0, rte_memory_order_relaxed);
+ update_datapath(device);
+
+ return 0;
+}
+
+static int
+nfp_vdpa_get_vfio_group_fd(int vid)
+{
+ struct rte_vdpa_device *vdev;
+ struct nfp_vdpa_dev_node *node;
+
+ vdev = rte_vhost_get_vdpa_device(vid);
+ node = nfp_vdpa_find_node_by_vdev(vdev);
+ if (node == NULL) {
+ DRV_VDPA_LOG(ERR, "Invalid vDPA device: %p", vdev);
+ return -ENODEV;
+ }
+
+ return node->device->vfio_group_fd;
+}
+
+static int
+nfp_vdpa_get_vfio_device_fd(int vid)
+{
+ struct rte_vdpa_device *vdev;
+ struct nfp_vdpa_dev_node *node;
+
+ vdev = rte_vhost_get_vdpa_device(vid);
+ node = nfp_vdpa_find_node_by_vdev(vdev);
+ if (node == NULL) {
+ DRV_VDPA_LOG(ERR, "Invalid vDPA device: %p", vdev);
+ return -ENODEV;
+ }
+
+ return node->device->vfio_dev_fd;
+}
+
+static int
+nfp_vdpa_get_notify_area(int vid,
+ int qid,
+ uint64_t *offset,
+ uint64_t *size)
+{
+ int ret;
+ struct nfp_vdpa_dev *device;
+ struct rte_vdpa_device *vdev;
+ struct nfp_vdpa_dev_node *node;
+ struct vfio_region_info region = {
+ .argsz = sizeof(region)
+ };
+
+ vdev = rte_vhost_get_vdpa_device(vid);
+ node = nfp_vdpa_find_node_by_vdev(vdev);
+ if (node == NULL) {
+ DRV_VDPA_LOG(ERR, "Invalid vDPA device: %p", vdev);
+ return -ENODEV;
+ }
+
+ device = node->device;
+ region.index = device->hw.notify_region;
+
+ ret = ioctl(device->vfio_dev_fd, VFIO_DEVICE_GET_REGION_INFO, ®ion);
+ if (ret != 0) {
+ DRV_VDPA_LOG(ERR, "Get not get device region info.");
+ return -EIO;
+ }
+
+ *offset = nfp_vdpa_get_queue_notify_offset(&device->hw, qid) + region.offset;
+ *size = NFP_VDPA_NOTIFY_ADDR_INTERVAL;
+
+ return 0;
+}
+
+static int
+nfp_vdpa_get_queue_num(struct rte_vdpa_device *vdev,
+ uint32_t *queue_num)
+{
+ struct nfp_vdpa_dev_node *node;
+
+ node = nfp_vdpa_find_node_by_vdev(vdev);
+ if (node == NULL) {
+ DRV_VDPA_LOG(ERR, "Invalid vDPA device: %p", vdev);
+ return -ENODEV;
+ }
+
+ *queue_num = node->device->max_queues;
+
+ return 0;
+}
+
+static int
+nfp_vdpa_get_vdpa_features(struct rte_vdpa_device *vdev,
+ uint64_t *features)
+{
+ struct nfp_vdpa_dev_node *node;
+
+ node = nfp_vdpa_find_node_by_vdev(vdev);
+ if (node == NULL) {
+ DRV_VDPA_LOG(ERR, "Invalid vDPA device: %p", vdev);
+ return -ENODEV;
+ }
+
+ *features = node->device->hw.features;
+
+ return 0;
+}
+
+static int
+nfp_vdpa_get_protocol_features(struct rte_vdpa_device *vdev __rte_unused,
+ uint64_t *features)
+{
+ *features = 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD |
+ 1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK |
+ 1ULL << VHOST_USER_PROTOCOL_F_BACKEND_REQ |
+ 1ULL << VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD |
+ 1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER;
+
+ return 0;
+}
+
+static int
+nfp_vdpa_set_features(int32_t vid)
+{
+ DRV_VDPA_LOG(DEBUG, "Start vid=%d", vid);
+ return 0;
+}
+
+static int
+nfp_vdpa_set_vring_state(int vid,
+ int vring,
+ int state)
+{
+ DRV_VDPA_LOG(DEBUG, "Start vid=%d, vring=%d, state=%d", vid, vring, state);
+ return 0;
+}
+
struct rte_vdpa_dev_ops nfp_vdpa_ops = {
+ .get_queue_num = nfp_vdpa_get_queue_num,
+ .get_features = nfp_vdpa_get_vdpa_features,
+ .get_protocol_features = nfp_vdpa_get_protocol_features,
+ .dev_conf = nfp_vdpa_dev_config,
+ .dev_close = nfp_vdpa_dev_close,
+ .set_vring_state = nfp_vdpa_set_vring_state,
+ .set_features = nfp_vdpa_set_features,
+ .get_vfio_group_fd = nfp_vdpa_get_vfio_group_fd,
+ .get_vfio_device_fd = nfp_vdpa_get_vfio_device_fd,
+ .get_notify_area = nfp_vdpa_get_notify_area,
};
static int
--
2.39.1
next prev parent reply other threads:[~2023-10-27 3:04 UTC|newest]
Thread overview: 121+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-17 5:45 [PATCH 00/25] add the NFP vDPA PMD Chaoyong He
2023-10-17 5:45 ` [PATCH 01/25] drivers: introduce the NFP common library Chaoyong He
2023-10-17 5:45 ` [PATCH 02/25] net/nfp: make VF PMD using of NFP common module Chaoyong He
2023-10-17 5:45 ` [PATCH 03/25] net/nfp: rename common module name Chaoyong He
2023-10-17 5:45 ` [PATCH 04/25] net/nfp: rename ctrl " Chaoyong He
2023-10-17 5:45 ` [PATCH 05/25] net/nfp: extract the cap data field Chaoyong He
2023-10-17 5:45 ` [PATCH 06/25] net/nfp: extract the qcp " Chaoyong He
2023-10-17 5:45 ` [PATCH 07/25] net/nfp: extract the ctrl BAR " Chaoyong He
2023-10-17 5:45 ` [PATCH 08/25] net/nfp: extract the ctrl " Chaoyong He
2023-10-17 5:45 ` [PATCH 09/25] net/nfp: change the parameter of APIs Chaoyong He
2023-10-17 5:45 ` [PATCH 10/25] net/nfp: change the parameter of reconfig Chaoyong He
2023-10-17 5:45 ` [PATCH 11/25] net/nfp: extract the MAC address data field Chaoyong He
2023-10-17 5:45 ` [PATCH 12/25] net/nfp: rename parameter in related logic Chaoyong He
2023-10-17 5:45 ` [PATCH 13/25] drivers: add the common ctrl module Chaoyong He
2023-10-17 5:45 ` [PATCH 14/25] drivers: add the nfp common module Chaoyong He
2023-10-17 5:45 ` [PATCH 15/25] drivers: move queue logic to " Chaoyong He
2023-10-17 5:45 ` [PATCH 16/25] drivers: move platform module to common library Chaoyong He
2023-10-17 5:45 ` [PATCH 17/25] drivers: move device " Chaoyong He
2023-10-17 5:45 ` [PATCH 18/25] drivers/vdpa: introduce the NFP vDPA library Chaoyong He
2023-10-17 5:45 ` [PATCH 19/25] drivers: add the basic framework of vDPA PMD Chaoyong He
2023-10-17 5:45 ` [PATCH 20/25] vdpa/nfp: add the logic of remap PCI memory Chaoyong He
2023-10-17 5:45 ` [PATCH 21/25] vdpa/nfp: add the hardware init logic Chaoyong He
2023-10-17 5:45 ` [PATCH 22/25] drivers: add the datapath update logic Chaoyong He
2023-10-17 5:45 ` [PATCH 23/25] vdpa/nfp: add the notify related logic Chaoyong He
2023-10-17 5:45 ` [PATCH 24/25] vdpa/nfp: add nfp vDPA device operations Chaoyong He
2023-10-17 5:45 ` [PATCH 25/25] doc: add the common and vDPA document Chaoyong He
2023-10-24 2:28 ` [PATCH v2 00/25] add the NFP vDPA PMD Chaoyong He
2023-10-24 2:28 ` [PATCH v2 01/25] drivers: introduce the NFP common library Chaoyong He
2023-10-24 2:28 ` [PATCH v2 02/25] net/nfp: make VF PMD using of NFP common module Chaoyong He
2023-10-25 16:09 ` Ferruh Yigit
2023-10-26 1:34 ` Chaoyong He
2023-10-24 2:28 ` [PATCH v2 03/25] net/nfp: rename common module name Chaoyong He
2023-10-24 2:28 ` [PATCH v2 04/25] net/nfp: rename ctrl " Chaoyong He
2023-10-24 2:28 ` [PATCH v2 05/25] net/nfp: extract the cap data field Chaoyong He
2023-10-24 2:28 ` [PATCH v2 06/25] net/nfp: extract the qcp " Chaoyong He
2023-10-24 2:28 ` [PATCH v2 07/25] net/nfp: extract the ctrl BAR " Chaoyong He
2023-10-24 2:28 ` [PATCH v2 08/25] net/nfp: extract the ctrl " Chaoyong He
2023-10-24 2:28 ` [PATCH v2 09/25] net/nfp: change the parameter of APIs Chaoyong He
2023-10-24 2:28 ` [PATCH v2 10/25] net/nfp: change the parameter of reconfig Chaoyong He
2023-10-24 2:28 ` [PATCH v2 11/25] net/nfp: extract the MAC address data field Chaoyong He
2023-10-24 2:28 ` [PATCH v2 12/25] net/nfp: rename parameter in related logic Chaoyong He
2023-10-24 2:28 ` [PATCH v2 13/25] drivers: add the common ctrl module Chaoyong He
2023-10-24 2:28 ` [PATCH v2 14/25] drivers: add the nfp common module Chaoyong He
2023-10-24 2:28 ` [PATCH v2 15/25] drivers: move queue logic to " Chaoyong He
2023-10-24 2:28 ` [PATCH v2 16/25] drivers: move platform module to common library Chaoyong He
2023-10-24 2:28 ` [PATCH v2 17/25] drivers: move device " Chaoyong He
2023-10-24 2:28 ` [PATCH v2 18/25] drivers/vdpa: introduce the NFP vDPA library Chaoyong He
2023-10-25 16:09 ` Ferruh Yigit
2023-10-26 1:39 ` Chaoyong He
2023-10-24 2:28 ` [PATCH v2 19/25] drivers: add the basic framework of vDPA PMD Chaoyong He
2023-10-25 16:10 ` Ferruh Yigit
2023-10-26 1:39 ` Chaoyong He
2023-10-24 2:28 ` [PATCH v2 20/25] vdpa/nfp: add the logic of remap PCI memory Chaoyong He
2023-10-24 2:28 ` [PATCH v2 21/25] vdpa/nfp: add the hardware init logic Chaoyong He
2023-10-24 2:28 ` [PATCH v2 22/25] drivers: add the datapath update logic Chaoyong He
2023-10-24 2:28 ` [PATCH v2 23/25] vdpa/nfp: add the notify related logic Chaoyong He
2023-10-24 2:28 ` [PATCH v2 24/25] vdpa/nfp: add nfp vDPA device operations Chaoyong He
2023-10-24 2:28 ` [PATCH v2 25/25] doc: add the common and vDPA document Chaoyong He
2023-10-25 16:11 ` Ferruh Yigit
2023-10-26 1:41 ` Chaoyong He
2023-10-25 16:09 ` [PATCH v2 00/25] add the NFP vDPA PMD Ferruh Yigit
2023-10-26 1:33 ` Chaoyong He
2023-10-26 2:50 ` Chaoyong He
2023-10-26 11:30 ` Ferruh Yigit
2023-10-26 11:33 ` Chaoyong He
2023-10-26 6:42 ` [PATCH v3 " Chaoyong He
2023-10-26 6:43 ` [PATCH v3 01/25] drivers: introduce the NFP common library Chaoyong He
2023-10-26 6:43 ` [PATCH v3 02/25] net/nfp: make VF PMD using of NFP common module Chaoyong He
2023-10-26 6:43 ` [PATCH v3 03/25] net/nfp: rename common module name Chaoyong He
2023-10-26 6:43 ` [PATCH v3 04/25] net/nfp: rename ctrl " Chaoyong He
2023-10-26 6:43 ` [PATCH v3 05/25] net/nfp: extract the cap data field Chaoyong He
2023-10-26 6:43 ` [PATCH v3 06/25] net/nfp: extract the qcp " Chaoyong He
2023-10-26 6:43 ` [PATCH v3 07/25] net/nfp: extract the ctrl BAR " Chaoyong He
2023-10-26 6:43 ` [PATCH v3 08/25] net/nfp: extract the ctrl " Chaoyong He
2023-10-26 6:43 ` [PATCH v3 09/25] net/nfp: change the parameter of APIs Chaoyong He
2023-10-26 6:43 ` [PATCH v3 10/25] net/nfp: change the parameter of reconfig Chaoyong He
2023-10-26 6:43 ` [PATCH v3 11/25] net/nfp: extract the MAC address data field Chaoyong He
2023-10-26 6:43 ` [PATCH v3 12/25] net/nfp: rename parameter in related logic Chaoyong He
2023-10-26 6:43 ` [PATCH v3 13/25] drivers: add the common ctrl module Chaoyong He
2023-10-26 6:43 ` [PATCH v3 14/25] drivers: add the nfp common module Chaoyong He
2023-10-26 6:43 ` [PATCH v3 15/25] drivers: move queue logic to " Chaoyong He
2023-10-26 6:43 ` [PATCH v3 16/25] drivers: move platform module to common library Chaoyong He
2023-10-26 6:43 ` [PATCH v3 17/25] drivers: move device " Chaoyong He
2023-10-26 6:43 ` [PATCH v3 18/25] drivers/vdpa: introduce the NFP vDPA library Chaoyong He
2023-10-26 6:43 ` [PATCH v3 19/25] drivers: add the basic framework of vDPA PMD Chaoyong He
2023-10-26 6:43 ` [PATCH v3 20/25] vdpa/nfp: add the logic of remap PCI memory Chaoyong He
2023-10-26 6:43 ` [PATCH v3 21/25] vdpa/nfp: add the hardware init logic Chaoyong He
2023-10-26 6:43 ` [PATCH v3 22/25] drivers: add the datapath update logic Chaoyong He
2023-10-26 6:43 ` [PATCH v3 23/25] vdpa/nfp: add the notify related logic Chaoyong He
2023-10-26 6:43 ` [PATCH v3 24/25] vdpa/nfp: add nfp vDPA device operations Chaoyong He
2023-10-26 6:43 ` [PATCH v3 25/25] doc: add a entry in the release notes Chaoyong He
2023-10-26 14:55 ` Ferruh Yigit
2023-10-26 14:47 ` [PATCH v3 00/25] add the NFP vDPA PMD Ferruh Yigit
2023-10-26 14:55 ` Ferruh Yigit
2023-10-27 1:23 ` Chaoyong He
2023-10-27 2:59 ` [PATCH v4 00/24] " Chaoyong He
2023-10-27 2:59 ` [PATCH v4 01/24] common/nfp: introduce driver Chaoyong He
2023-10-27 2:59 ` [PATCH v4 02/24] net/nfp: make VF PMD use NFP common driver Chaoyong He
2023-10-27 2:59 ` [PATCH v4 03/24] net/nfp: rename net common module Chaoyong He
2023-10-27 2:59 ` [PATCH v4 04/24] net/nfp: rename ctrl module Chaoyong He
2023-10-27 2:59 ` [PATCH v4 05/24] net/nfp: extract cap data field Chaoyong He
2023-10-27 2:59 ` [PATCH v4 06/24] net/nfp: extract qcp " Chaoyong He
2023-10-27 2:59 ` [PATCH v4 07/24] net/nfp: extract ctrl BAR " Chaoyong He
2023-10-27 2:59 ` [PATCH v4 08/24] net/nfp: extract ctrl " Chaoyong He
2023-10-27 2:59 ` [PATCH v4 09/24] net/nfp: change parameter of functions Chaoyong He
2023-10-27 2:59 ` [PATCH v4 10/24] net/nfp: change parameter of reconfig Chaoyong He
2023-10-27 2:59 ` [PATCH v4 11/24] net/nfp: extract MAC address data field Chaoyong He
2023-10-27 2:59 ` [PATCH v4 12/24] net/nfp: rename parameter in related logic Chaoyong He
2023-10-27 2:59 ` [PATCH v4 13/24] common/nfp: add common ctrl module Chaoyong He
2023-10-27 2:59 ` [PATCH v4 14/24] common/nfp: add common module Chaoyong He
2023-10-27 2:59 ` [PATCH v4 15/24] common/nfp: move queue logic Chaoyong He
2023-10-27 2:59 ` [PATCH v4 16/24] common/nfp: move platform module Chaoyong He
2023-10-27 2:59 ` [PATCH v4 17/24] common/nfp: move device module Chaoyong He
2023-10-27 2:59 ` [PATCH v4 18/24] vdpa/nfp: introduce driver Chaoyong He
2023-10-27 2:59 ` [PATCH v4 19/24] vdpa/nfp: add basic framework Chaoyong He
2023-10-27 2:59 ` [PATCH v4 20/24] vdpa/nfp: add remap PCI memory Chaoyong He
2023-10-27 2:59 ` [PATCH v4 21/24] vdpa/nfp: add hardware init Chaoyong He
2023-10-27 2:59 ` [PATCH v4 22/24] vdpa/nfp: add datapath update Chaoyong He
2023-10-27 3:00 ` [PATCH v4 23/24] vdpa/nfp: add notify related logic Chaoyong He
2023-10-27 3:00 ` Chaoyong He [this message]
2023-10-27 13:38 ` [PATCH v4 00/24] add the NFP vDPA PMD Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231027030001.602639-25-chaoyong.he@corigine.com \
--to=chaoyong.he@corigine.com \
--cc=dev@dpdk.org \
--cc=long.wu@corigine.com \
--cc=oss-drivers@corigine.com \
--cc=peng.zhang@corigine.com \
--cc=shujing.dong@corigine.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).