From 82255e036acc95ff219af32ec9be385583d97368 Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Fri, 23 Oct 2020 04:59:58 -0400 Subject: [PATCH] raw/ifpga/base: free resources when destroying device 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 Signed-off-by: Tianfei Zhang Acked-by: Rosen Xu --- 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 6dbd7159e8..1ff57fa188 100644 --- a/drivers/raw/ifpga/base/ifpga_api.c +++ b/drivers/raw/ifpga/base/ifpga_api.c @@ -330,8 +330,20 @@ error: 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 b8846e3731..48b8af4587 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 14131e3206..95ed594cdc 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 fdeb713ff6..0385514cdc 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.c +++ b/drivers/raw/ifpga/ifpga_rawdev.c @@ -715,6 +715,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; } @@ -1530,6 +1540,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!"); @@ -1549,6 +1560,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) @@ -1562,9 +1576,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.20.1