[14/20] net/softnic: release port upon close
diff mbox series

Message ID 20200913220711.3768597-15-thomas@monjalon.net
State Changes Requested
Delegated to: Ferruh Yigit
Headers show
Series
  • cleanup ethdev close operation
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon Sept. 13, 2020, 10:07 p.m. UTC
The flag RTE_ETH_DEV_CLOSE_REMOVE is set so all port resources
can be freed by rte_eth_dev_close().

Freeing of private port resources is moved
from the ".remove(device)" to the ".dev_close(port)" operation.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 drivers/net/softnic/rte_eth_softnic.c | 63 ++++++++++++++-------------
 1 file changed, 32 insertions(+), 31 deletions(-)

Comments

Dumitrescu, Cristian Sept. 14, 2020, 3:21 p.m. UTC | #1
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Sunday, September 13, 2020 11:07 PM
> To: dev@dpdk.org
> Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; arybchenko@solarflare.com;
> Singh, Jasvinder <jasvinder.singh@intel.com>; Dumitrescu, Cristian
> <cristian.dumitrescu@intel.com>
> Subject: [PATCH 14/20] net/softnic: release port upon close
> 
> The flag RTE_ETH_DEV_CLOSE_REMOVE is set so all port resources
> can be freed by rte_eth_dev_close().
> 
> Freeing of private port resources is moved
> from the ".remove(device)" to the ".dev_close(port)" operation.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---

Thanks for doing this work, Thomas!

Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>

Patch
diff mbox series

diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c
index 491a308c11..5b94e250d8 100644
--- a/drivers/net/softnic/rte_eth_softnic.c
+++ b/drivers/net/softnic/rte_eth_softnic.c
@@ -201,9 +201,37 @@  pmd_dev_stop(struct rte_eth_dev *dev)
 	softnic_mtr_free(p);
 }
 
+static void
+pmd_free(struct pmd_internals *p)
+{
+	if (p == NULL)
+		return;
+
+	if (p->params.conn_port)
+		softnic_conn_free(p->conn);
+
+	softnic_thread_free(p);
+	softnic_pipeline_free(p);
+	softnic_table_action_profile_free(p);
+	softnic_port_in_action_profile_free(p);
+	softnic_tap_free(p);
+	softnic_tmgr_free(p);
+	softnic_link_free(p);
+	softnic_swq_free(p);
+	softnic_mempool_free(p);
+
+	tm_hierarchy_free(p);
+	softnic_mtr_free(p);
+
+	rte_free(p);
+}
+
 static int
-pmd_dev_close(struct rte_eth_dev *dev __rte_unused)
+pmd_dev_close(struct rte_eth_dev *dev)
 {
+	pmd_free(dev->data->dev_private);
+	dev->data->dev_private = NULL; /* already freed */
+	dev->data->mac_addrs = NULL; /* statically allocated */
 	return 0;
 }
 
@@ -335,31 +363,6 @@  pmd_init(struct pmd_params *params)
 	return p;
 }
 
-static void
-pmd_free(struct pmd_internals *p)
-{
-	if (p == NULL)
-		return;
-
-	if (p->params.conn_port)
-		softnic_conn_free(p->conn);
-
-	softnic_thread_free(p);
-	softnic_pipeline_free(p);
-	softnic_table_action_profile_free(p);
-	softnic_port_in_action_profile_free(p);
-	softnic_tap_free(p);
-	softnic_tmgr_free(p);
-	softnic_link_free(p);
-	softnic_swq_free(p);
-	softnic_mempool_free(p);
-
-	tm_hierarchy_free(p);
-	softnic_mtr_free(p);
-
-	rte_free(p);
-}
-
 static struct rte_ether_addr eth_addr = {
 	.addr_bytes = {0},
 };
@@ -384,6 +387,7 @@  pmd_ethdev_register(struct rte_vdev_device *vdev,
 	dev->device = &vdev->device;
 
 	/* dev->data */
+	dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
 	dev->data->dev_private = dev_private;
 	dev->data->dev_link.link_speed = ETH_SPEED_NUM_100G;
 	dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
@@ -653,12 +657,9 @@  pmd_remove(struct rte_vdev_device *vdev)
 	/* Find the ethdev entry */
 	dev = rte_eth_dev_allocated(rte_vdev_device_name(vdev));
 	if (dev == NULL)
-		return -ENODEV;
+		return 0; /* port already released */
 
-	/* Free device data structures*/
-	pmd_free(dev->data->dev_private);
-	dev->data->dev_private = NULL; /* already freed */
-	dev->data->mac_addrs = NULL; /* statically allocated */
+	pmd_dev_close(dev);
 	rte_eth_dev_release_port(dev);
 
 	return 0;