DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tianfei zhang <tianfei.zhang@intel.com>
To: dev@dpdk.org , rosen.xu@intel.com, qi.z.zhang@intel.com
Cc: Wei Huang <wei.huang@intel.com>, Tianfei zhang <tianfei.zhang@intel.com>
Subject: [dpdk-dev] [PATCH v3 4/5] raw/ifpga/base: free resources when destroying ifpga device
Date: Fri, 23 Oct 2020 04:59:58 -0400
Message-ID: <1603443599-7356-5-git-send-email-tianfei.zhang@intel.com> (raw)
In-Reply-To: <1603443599-7356-1-git-send-email-tianfei.zhang@intel.com>

From: Wei Huang <wei.huang@intel.com>

Add two functions to complete the resource free work, one is
'ifpga_adapter_destroy()', the other is 'ifpga_bus_uinit()'.

Then call 'opae_adapter_destroy()' and 'opae_adapter_data_free()'
in 'ifpga_rawdev_close()' to free resources.

Also 'opae_adapter_free()' is removed from 'ifpga_rawdev_destroy()',
because opae adapter is pointed by dev_private member in raw_dev,
it will be freed in 'rte_rawdev_pmd_release()'.

Signed-off-by: Wei Huang <wei.huang@intel.com>
Signed-off-by: Tianfei zhang <tianfei.zhang@intel.com>

---
v3: Free the driver resouce on rawdev close ops.
---
 drivers/raw/ifpga/base/ifpga_api.c       | 12 ++++++++++++
 drivers/raw/ifpga/base/ifpga_enumerate.c | 16 ++++++++++++++++
 drivers/raw/ifpga/base/ifpga_enumerate.h |  1 +
 drivers/raw/ifpga/ifpga_rawdev.c         | 17 ++++++++++++++---
 4 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/drivers/raw/ifpga/base/ifpga_api.c b/drivers/raw/ifpga/base/ifpga_api.c
index 6dbd7159e..1ff57fa18 100644
--- a/drivers/raw/ifpga/base/ifpga_api.c
+++ b/drivers/raw/ifpga/base/ifpga_api.c
@@ -330,8 +330,20 @@ static int ifpga_adapter_enumerate(struct opae_adapter *adapter)
 	return -ENOMEM;
 }
 
+static void ifpga_adapter_destroy(struct opae_adapter *adapter)
+{
+	struct ifpga_fme_hw *fme;
+
+	if (adapter && adapter->mgr && adapter->mgr->data) {
+		fme = (struct ifpga_fme_hw *)adapter->mgr->data;
+		if (fme->parent)
+			ifpga_bus_uinit(fme->parent);
+	}
+}
+
 struct opae_adapter_ops ifpga_adapter_ops = {
 	.enumerate = ifpga_adapter_enumerate,
+	.destroy = ifpga_adapter_destroy,
 };
 
 /**
diff --git a/drivers/raw/ifpga/base/ifpga_enumerate.c b/drivers/raw/ifpga/base/ifpga_enumerate.c
index b8846e373..48b8af458 100644
--- a/drivers/raw/ifpga/base/ifpga_enumerate.c
+++ b/drivers/raw/ifpga/base/ifpga_enumerate.c
@@ -722,3 +722,19 @@ int ifpga_bus_init(struct ifpga_hw *hw)
 
 	return 0;
 }
+
+int ifpga_bus_uinit(struct ifpga_hw *hw)
+{
+	int i;
+	struct ifpga_port_hw *port;
+
+	if (hw) {
+		fme_hw_uinit(&hw->fme);
+		for (i = 0; i < MAX_FPGA_PORT_NUM; i++) {
+			port = &hw->port[i];
+			port_hw_uinit(port);
+		}
+	}
+
+	return 0;
+}
diff --git a/drivers/raw/ifpga/base/ifpga_enumerate.h b/drivers/raw/ifpga/base/ifpga_enumerate.h
index 14131e320..95ed594cd 100644
--- a/drivers/raw/ifpga/base/ifpga_enumerate.h
+++ b/drivers/raw/ifpga/base/ifpga_enumerate.h
@@ -6,6 +6,7 @@
 #define _IFPGA_ENUMERATE_H_
 
 int ifpga_bus_init(struct ifpga_hw *hw);
+int ifpga_bus_uinit(struct ifpga_hw *hw);
 int ifpga_bus_enumerate(struct ifpga_hw *hw);
 
 #endif /* _IFPGA_ENUMERATE_H_ */
diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
index 04ca5032a..6de5b8cae 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.c
+++ b/drivers/raw/ifpga/ifpga_rawdev.c
@@ -720,6 +720,16 @@ ifpga_rawdev_stop(struct rte_rawdev *dev)
 static int
 ifpga_rawdev_close(struct rte_rawdev *dev)
 {
+	struct opae_adapter *adapter;
+
+	if (dev) {
+		adapter = ifpga_rawdev_get_priv(dev);
+		if (adapter) {
+			opae_adapter_destroy(adapter);
+			opae_adapter_data_free(adapter->data);
+		}
+	}
+
 	return dev ? 0:1;
 }
 
@@ -1535,6 +1545,7 @@ ifpga_rawdev_destroy(struct rte_pci_device *pci_dev)
 	char name[RTE_RAWDEV_NAME_MAX_LEN];
 	struct opae_adapter *adapter;
 	struct opae_manager *mgr;
+	struct ifpga_rawdev *dev;
 
 	if (!pci_dev) {
 		IFPGA_RAWDEV_PMD_ERR("Invalid pci_dev of the device!");
@@ -1554,6 +1565,9 @@ ifpga_rawdev_destroy(struct rte_pci_device *pci_dev)
 		IFPGA_RAWDEV_PMD_ERR("Invalid device name (%s)", name);
 		return -EINVAL;
 	}
+	dev = ifpga_rawdev_get(rawdev);
+	if (dev)
+		dev->rawdev = NULL;
 
 	adapter = ifpga_rawdev_get_priv(rawdev);
 	if (!adapter)
@@ -1567,9 +1581,6 @@ ifpga_rawdev_destroy(struct rte_pci_device *pci_dev)
 				fme_interrupt_handler, mgr) < 0)
 		return -EINVAL;
 
-	opae_adapter_data_free(adapter->data);
-	opae_adapter_free(adapter);
-
 	/* rte_rawdev_close is called by pmd_release */
 	ret = rte_rawdev_pmd_release(rawdev);
 	if (ret)
-- 
2.17.1


  parent reply	other threads:[~2020-10-23 10:01 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23  7:30 [dpdk-dev] [PATCH v4 0/4] raw/ifpga/base: An inprovement for multi-process Tianfei zhang
2020-09-23  7:30 ` [dpdk-dev] [PATCH v4 1/4] raw/ifpga/base: fix bug in IRQ functions Tianfei zhang
2020-09-23  7:30 ` [dpdk-dev] [PATCH v4 2/4] raw/ifpga/base: free resources when destroying ifpga device Tianfei zhang
2020-09-23  7:30 ` [dpdk-dev] [PATCH v4 3/4] raw/ifpga/base: cleanup ifpga raw devices when process quit Tianfei zhang
2020-09-23  7:30 ` [dpdk-dev] [PATCH v4 4/4] raw/ifpga/base: enhance driver reliablity in multi-process Tianfei zhang
2020-09-28  1:40 ` [dpdk-dev] [PATCH v2 0/4] raw/ifpga/base: An improvement for multi-process Tianfei zhang
2020-09-28  1:40   ` [dpdk-dev] [PATCH v2 1/4] raw/ifpga/base: fix bug in IRQ functions Tianfei zhang
2020-09-29  1:42     ` Xu, Rosen
2020-10-14  9:59       ` Zhang, Tianfei
2020-10-15 13:14       ` Zhang, Qi Z
2020-10-15 18:56     ` Ferruh Yigit
2020-10-16  5:46       ` Zhang, Tianfei
2020-09-28  1:40   ` [dpdk-dev] [PATCH v2 2/4] raw/ifpga/base: free resources when destroying ifpga device Tianfei zhang
2020-09-29  1:42     ` Xu, Rosen
2020-10-15 13:15       ` Zhang, Qi Z
2020-10-15 18:57     ` Ferruh Yigit
2020-10-16  5:51       ` Zhang, Tianfei
2020-09-28  1:40   ` [dpdk-dev] [PATCH v2 3/4] raw/ifpga/base: cleanup ifpga raw devices when process quit Tianfei zhang
2020-09-29  1:43     ` Xu, Rosen
2020-10-15 13:15       ` Zhang, Qi Z
2020-10-15 18:57     ` Ferruh Yigit
2020-10-16  5:54       ` Zhang, Tianfei
2020-09-28  1:40   ` [dpdk-dev] [PATCH v2 4/4] raw/ifpga/base: enhance driver reliability in multi-process Tianfei zhang
2020-10-15  6:08     ` Xu, Rosen
2020-10-15 13:16       ` Zhang, Qi Z
2020-10-23  8:59 ` [dpdk-dev] [PATCH v3 0/5] raw/ifpga/base: An improvement for multi-process Tianfei zhang
2020-10-23  8:59   ` [dpdk-dev] [PATCH v3 1/5] raw/ifpga/base: fix interrupt handler instance usage Tianfei zhang
2020-10-23  8:59   ` [dpdk-dev] [PATCH v3 2/5] raw/ifpga/base: handle unsupported interrupt type Tianfei zhang
2020-10-23  8:59   ` [dpdk-dev] [PATCH v3 3/5] raw/ifpga/base: fix return of IRQ unregister properly Tianfei zhang
2020-10-23  8:59   ` Tianfei zhang [this message]
2020-10-23  8:59   ` [dpdk-dev] [PATCH v3 5/5] raw/ifpga/base: enhance driver reliablity in multi-process Tianfei zhang
2020-10-26  1:04   ` [dpdk-dev] [PATCH v3 0/5] raw/ifpga/base: An improvement for multi-process Zhang, Qi Z
2020-10-23  9:06 ` Tianfei zhang

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=1603443599-7356-5-git-send-email-tianfei.zhang@intel.com \
    --to=tianfei.zhang@intel.com \
    --cc=dev@dpdk.org \
    --cc=wei.huang@intel.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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git