net/nfb: remove resources when dev is closed

Message ID 1565362745-152027-1-git-send-email-cernay@netcope.com
State Superseded
Delegated to: Ferruh Yigit
Headers show
Series
  • net/nfb: remove resources when dev is closed
Related show

Checks

Context Check Description
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS
ci/iol-Compile-Testing success Compile Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Rastislav Cernay Aug. 9, 2019, 2:59 p.m.
From: Rastislav Cernay <cernay@netcope.com>

The rte_eth_dev_close() function now handles freeing resources for
devices (e.g., mac_addrs).  To conform with the new close() behaviour we
are asserting the RTE_ETH_DEV_CLOSE_REMOVE flag so that
rte_eth_dev_close() releases all device level dynamic memory.

Signed-off-by: Rastislav Cernay <cernay@netcope.com>
---
 drivers/net/nfb/nfb_ethdev.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

Jan Remeš Aug. 9, 2019, 3:01 p.m. | #1
Acked-by: Jan Remes <remes@netcope.com>

On Fri, Aug 9, 2019 at 4:59 PM Rastislav Cernay <cernay@netcope.com> wrote:
>
> From: Rastislav Cernay <cernay@netcope.com>
>
> The rte_eth_dev_close() function now handles freeing resources for
> devices (e.g., mac_addrs).  To conform with the new close() behaviour we
> are asserting the RTE_ETH_DEV_CLOSE_REMOVE flag so that
> rte_eth_dev_close() releases all device level dynamic memory.
>
> Signed-off-by: Rastislav Cernay <cernay@netcope.com>
> ---
>  drivers/net/nfb/nfb_ethdev.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/nfb/nfb_ethdev.c b/drivers/net/nfb/nfb_ethdev.c
> index c3119a0..4a19979 100644
> --- a/drivers/net/nfb/nfb_ethdev.c
> +++ b/drivers/net/nfb/nfb_ethdev.c
> @@ -210,12 +210,17 @@
>  static void
>  nfb_eth_dev_close(struct rte_eth_dev *dev)
>  {
> +       struct pmd_internals *internals = (struct pmd_internals *)
> +               dev->data->dev_private;
>         uint16_t i;
>         uint16_t nb_rx = dev->data->nb_rx_queues;
>         uint16_t nb_tx = dev->data->nb_tx_queues;
>
>         nfb_eth_dev_stop(dev);
>
> +       nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
> +       nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
> +
>         for (i = 0; i < nb_rx; i++) {
>                 nfb_eth_rx_queue_release(dev->data->rx_queues[i]);
>                 dev->data->rx_queues[i] = NULL;
> @@ -226,6 +231,9 @@
>                 dev->data->tx_queues[i] = NULL;
>         }
>         dev->data->nb_tx_queues = 0;
> +
> +       rte_free(dev->data->mac_addrs);
> +       dev->data->mac_addrs = NULL;
>  }
>
>  /**
> @@ -446,6 +454,9 @@
>                 rte_kvargs_free(kvlist);
>         }
>
> +       /* Let rte_eth_dev_close() release the port resources */
> +       dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
> +
>         /*
>          * Get number of available DMA RX and TX queues, which is maximum
>          * number of queues that can be created and store it in private device
> @@ -520,15 +531,10 @@
>  static int
>  nfb_eth_dev_uninit(struct rte_eth_dev *dev)
>  {
> -       struct rte_eth_dev_data *data = dev->data;
> -       struct pmd_internals *internals = (struct pmd_internals *)
> -               data->dev_private;
> -
>         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
>         struct rte_pci_addr *pci_addr = &pci_dev->addr;
>
> -       nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
> -       nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
> +       nfb_eth_dev_close(dev);
>
>         RTE_LOG(INFO, PMD, "NFB device ("
>                 PCI_PRI_FMT ") successfully uninitialized\n",
> --
> 1.8.3.1
>
Ye Xiaolong Aug. 10, 2019, 12:51 p.m. | #2
On 08/09, Rastislav Cernay wrote:
>From: Rastislav Cernay <cernay@netcope.com>
>
>The rte_eth_dev_close() function now handles freeing resources for
>devices (e.g., mac_addrs).  To conform with the new close() behaviour we
>are asserting the RTE_ETH_DEV_CLOSE_REMOVE flag so that
>rte_eth_dev_close() releases all device level dynamic memory.
>
>Signed-off-by: Rastislav Cernay <cernay@netcope.com>
>---
> drivers/net/nfb/nfb_ethdev.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
>
>diff --git a/drivers/net/nfb/nfb_ethdev.c b/drivers/net/nfb/nfb_ethdev.c
>index c3119a0..4a19979 100644
>--- a/drivers/net/nfb/nfb_ethdev.c
>+++ b/drivers/net/nfb/nfb_ethdev.c
>@@ -210,12 +210,17 @@
> static void
> nfb_eth_dev_close(struct rte_eth_dev *dev)
> {
>+	struct pmd_internals *internals = (struct pmd_internals *)
>+		dev->data->dev_private;

The device private pointer (dev_private) is of type void *, therefore this
cast is unnecessary.

> 	uint16_t i;
> 	uint16_t nb_rx = dev->data->nb_rx_queues;
> 	uint16_t nb_tx = dev->data->nb_tx_queues;
> 
> 	nfb_eth_dev_stop(dev);
> 
>+	nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
>+	nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
>+
> 	for (i = 0; i < nb_rx; i++) {
> 		nfb_eth_rx_queue_release(dev->data->rx_queues[i]);
> 		dev->data->rx_queues[i] = NULL;
>@@ -226,6 +231,9 @@
> 		dev->data->tx_queues[i] = NULL;
> 	}
> 	dev->data->nb_tx_queues = 0;
>+
>+	rte_free(dev->data->mac_addrs);
>+	dev->data->mac_addrs = NULL;
> }
> 
> /**
>@@ -446,6 +454,9 @@
> 		rte_kvargs_free(kvlist);
> 	}
> 
>+	/* Let rte_eth_dev_close() release the port resources */
>+	dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
>+
> 	/*
> 	 * Get number of available DMA RX and TX queues, which is maximum
> 	 * number of queues that can be created and store it in private device
>@@ -520,15 +531,10 @@
> static int
> nfb_eth_dev_uninit(struct rte_eth_dev *dev)
> {
>-	struct rte_eth_dev_data *data = dev->data;
>-	struct pmd_internals *internals = (struct pmd_internals *)
>-		data->dev_private;
>-
> 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
> 	struct rte_pci_addr *pci_addr = &pci_dev->addr;
> 
>-	nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
>-	nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
>+	nfb_eth_dev_close(dev);
> 
> 	RTE_LOG(INFO, PMD, "NFB device ("
> 		PCI_PRI_FMT ") successfully uninitialized\n",
>-- 
>1.8.3.1
>

For the rest,

Reviewed-by: Xiaolong Ye <xiaolong.ye@intel.com>

Patch

diff --git a/drivers/net/nfb/nfb_ethdev.c b/drivers/net/nfb/nfb_ethdev.c
index c3119a0..4a19979 100644
--- a/drivers/net/nfb/nfb_ethdev.c
+++ b/drivers/net/nfb/nfb_ethdev.c
@@ -210,12 +210,17 @@ 
 static void
 nfb_eth_dev_close(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	uint16_t i;
 	uint16_t nb_rx = dev->data->nb_rx_queues;
 	uint16_t nb_tx = dev->data->nb_tx_queues;
 
 	nfb_eth_dev_stop(dev);
 
+	nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
+	nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
+
 	for (i = 0; i < nb_rx; i++) {
 		nfb_eth_rx_queue_release(dev->data->rx_queues[i]);
 		dev->data->rx_queues[i] = NULL;
@@ -226,6 +231,9 @@ 
 		dev->data->tx_queues[i] = NULL;
 	}
 	dev->data->nb_tx_queues = 0;
+
+	rte_free(dev->data->mac_addrs);
+	dev->data->mac_addrs = NULL;
 }
 
 /**
@@ -446,6 +454,9 @@ 
 		rte_kvargs_free(kvlist);
 	}
 
+	/* Let rte_eth_dev_close() release the port resources */
+	dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
+
 	/*
 	 * Get number of available DMA RX and TX queues, which is maximum
 	 * number of queues that can be created and store it in private device
@@ -520,15 +531,10 @@ 
 static int
 nfb_eth_dev_uninit(struct rte_eth_dev *dev)
 {
-	struct rte_eth_dev_data *data = dev->data;
-	struct pmd_internals *internals = (struct pmd_internals *)
-		data->dev_private;
-
 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 	struct rte_pci_addr *pci_addr = &pci_dev->addr;
 
-	nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
-	nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
+	nfb_eth_dev_close(dev);
 
 	RTE_LOG(INFO, PMD, "NFB device ("
 		PCI_PRI_FMT ") successfully uninitialized\n",