Thread (46 messages) 46 messages, 7 authors, 2024-02-12

Re: [dpdk-dev] [PATCH 4/8] emu/iavf: add vfio-user device register and unregister

From: Xia, Chenbo <hidden>
Date: 2021-01-07 08:42:04

Hi Beilei,
-----Original Message-----
From: Xing, Beilei <redacted>
Sent: Thursday, January 7, 2021 3:19 PM
To: Xia, Chenbo <redacted>; dev@dpdk.org; thomas@monjalon.net;
david.marchand@redhat.com
Cc: stephen@networkplumber.org; Liang, Cunming <redacted>; Lu,
Xiuchun [off-list ref]; Li, Miao [off-list ref]; Wu, Jingjing
[off-list ref]
Subject: RE: [dpdk-dev] [PATCH 4/8] emu/iavf: add vfio-user device register
and unregister


quoted
-----Original Message-----
From: dev <redacted> On Behalf Of Chenbo Xia
Sent: Friday, December 18, 2020 3:48 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 4/8] emu/iavf: add vfio-user device register and
unregister

This patch adds vfio-user APIs call in driver probe and remove.
rte_vfio_user_register() and rte_vfio_user_unregister() are called to
create/destroy a vfio-user device. Notify callbacks that libvfio_user
defines are
quoted
also implemented.

Signed-off-by: Chenbo Xia <redacted>
Signed-off-by: Miao Li <redacted>
---
quoted
+static struct iavf_emudev *find_iavf_with_dev_id(int vfio_dev_id) {
It's better to change the function name to follow other function names' style.
iavf_emu_xxx
OK, thanks!
quoted
+	struct iavf_emu_sock_list *list;
+	char sock_addr[PATH_MAX];
+	int ret;
+
+	ret = rte_vfio_get_sock_addr(vfio_dev_id, sock_addr,
+		sizeof(sock_addr));
+	if (ret) {
+		EMU_IAVF_LOG(ERR, "Can not find vfio device %d "
+			"sock_addr.\n", vfio_dev_id);
+		return NULL;
+	}
+
+	list = iavf_emu_find_sock_list(sock_addr);
+	if (!list) {
+		EMU_IAVF_LOG(ERR, "Can not find sock list.\n");
+		return NULL;
+	}
+
+	return (struct iavf_emudev *)list->emu_dev->priv_data; }
It's better to check if list->emu_dev is NULL first.
'list->emu_dev->priv_data' is already used in iavf_emu_find_sock_list.
And based on the way we add to the list, emu_dev will not be NULL.
But thanks to your comment, I noticed I should just return struct iavf_emudev
in iavf_emu_find_sock_list. And the linked list may just store
'struct iavf_emudev' to make it easier.
quoted
+
+static int iavf_emu_new_device(int vfio_dev_id) {
+	struct iavf_emudev *dev;
+	int ret;
+
+	dev = find_iavf_with_dev_id(vfio_dev_id);
+	if (!dev)
+		return -1;
+
+	dev->vfio->dev_id = vfio_dev_id;
+
+	ret = iavf_emu_setup_mem_table(dev);
+	if (ret) {
+		EMU_IAVF_LOG(ERR, "Failed to set up memtable for "
+			"device %d", dev->vfio->dev_id);
+		return ret;
+	}
+
+	ret = iavf_emu_setup_irq(dev);
+	if (ret) {
+		EMU_IAVF_LOG(ERR, "Failed to set up irq for "
+			"device %d", dev->vfio->dev_id);
+		return ret;
+	}
+
+	ret = iavf_emu_setup_queues(dev);
+	if (ret) {
+		EMU_IAVF_LOG(ERR, "Failed to set up queues for "
+			"device %d", dev->vfio->dev_id);
+		return ret;
+	}
+
+	ret = dev->ops->device_ready(dev->edev);
Same as above, and please also check other functions, such as device_destroy...
Yes! Will add check then.
quoted
+	if (ret)
+		return ret;
+
+	dev->ready = 1;
+	return 0;
+}
+
+static void iavf_emu_destroy_device(int vfio_dev_id) {
+	struct iavf_emudev *dev;
+
+	dev = find_iavf_with_dev_id(vfio_dev_id);
+	if (!dev)
+		return;
+
+	iavf_emu_reset_all_resources(dev);
Should we add 'dev->ready = 0' here?
Yes. Will fix it.
quoted
+
+	dev->ops->device_destroy(dev->edev);
+}
+

quoted
+static int iavf_emu_lock_datapath(int vfio_dev_id, int lock) {
+	struct iavf_emudev *dev;
+
+	dev = find_iavf_with_dev_id(vfio_dev_id);
+	if (!dev)
+		return -1;
+
+	return dev->ops->lock_dp(dev->edev, lock); }
+
+static int iavf_emu_reset_device(int vfio_dev_id) {
+	struct iavf_emudev *dev;
+
+	dev = find_iavf_with_dev_id(vfio_dev_id);
+	if (!dev)
+		return -1;
+
+	iavf_emu_reset_all_resources(dev);
Should we add 'dev->ready = 0' here?
Yes. Will fix it.

Thanks,
Chenbo
quoted
+
+	return dev->ops->reset_device(dev->edev);
+}
+
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help