Re: [dpdk-dev] [PATCH 7/9] vfio_user: add client APIs of DMA/IRQ/region
From: Xing, Beilei <hidden>
Date: 2021-01-07 02:41:43
quoted hunk ↗ jump to hunk
-----Original Message----- From: dev <redacted> On Behalf Of Chenbo Xia Sent: Friday, December 18, 2020 3:39 PM To: dev@dpdk.org; thomas@monjalon.net; david.marchand@redhat.com Cc: stephen@networkplumber.org; Liang, Cunming [off-list ref]; Lu, Xiuchun [off-list ref]; Li, Miao [off-list ref]; Wu, Jingjing [off-list ref] Subject: [dpdk-dev] [PATCH 7/9] vfio_user: add client APIs of DMA/IRQ/region This patch introduces nine APIs - Device related: rte_vfio_user_get_dev_info and rte_vfio_user_reset - DMA related: rte_vfio_user_dma_map/unmap - Region related: rte_vfio_user_get_reg_info and rte_vfio_user_region_read/write - IRQ related: rte_vfio_user_get_irq_info and rte_vfio_user_set_irqs Signed-off-by: Chenbo Xia <redacted> Signed-off-by: Xiuchun Lu <redacted> --- lib/librte_vfio_user/rte_vfio_user.h | 168 ++++++++++ lib/librte_vfio_user/version.map | 9 + lib/librte_vfio_user/vfio_user_client.c | 412 ++++++++++++++++++++++++ 3 files changed, 589 insertions(+)diff --git a/lib/librte_vfio_user/rte_vfio_user.hb/lib/librte_vfio_user/rte_vfio_user.h index b09d83e224..fe27d05992 100644--- a/lib/librte_vfio_user/rte_vfio_user.h +++ b/lib/librte_vfio_user/rte_vfio_user.h@@ -229,6 +229,15 @@ int rte_vfio_user_set_irq_info(const char *sock_addr,
+int rte_vfio_user_get_dev_info(int dev_id, struct vfio_device_info
+*info) {
+ VFIO_USER_MSG msg;
+ struct vfio_user_client *dev;
+ int ret;
+ uint32_t sz = VFIO_USER_MSG_HDR_SIZE + sizeof(struct
+vfio_device_info);
+
+ if (!info)
+ return -EINVAL;
+
+ dev = vfio_client_devs.cl[dev_id];
+ if (!dev) {
+ VFIO_USER_LOG(ERR, "Failed to get device info: "
+ "wrong device ID\n");
+ return -EINVAL;
+ }
+
+ memset(&msg, 0, sizeof(VFIO_USER_MSG));
+ vfio_user_client_fill_hdr(&msg, VFIO_USER_DEVICE_GET_INFO, sz);
+
+ ret = vfio_user_client_send_recv(dev->sock.sock_fd, &msg);
+ if (ret)
+ return ret;
+
+ if (msg.flags & VFIO_USER_ERROR) {
+ VFIO_USER_LOG(ERR, "Failed to get device info: %s\n",
+ msg.err ? strerror(msg.err) : "Unknown error");
+ return msg.err ? -(int)msg.err : -1;
+ }
+
+ if (vfio_user_check_msg_fdnum(&msg, 0) != 0)
+ return -1;
+
+ memcpy(info, &msg.payload.dev_info, sizeof(*info));
+ return ret;
+}
+Seems there's duplicate code in function get_xxx_info, double check and refine.