DPDK patches and discussions
 help / color / mirror / Atom feed
From: Di ChenxuX <chenxux.di@intel.com>
To: dev@dpdk.org
Cc: qiming.yang@intel.com, Di ChenxuX <chenxux.di@intel.com>
Subject: [dpdk-dev] [PATCH v5 5/5] net/ixgbe: release port upon close
Date: Thu, 26 Sep 2019 07:30:08 +0000	[thread overview]
Message-ID: <20190926073008.46653-6-chenxux.di@intel.com> (raw)
In-Reply-To: <20190926073008.46653-1-chenxux.di@intel.com>
In-Reply-To: <20190827050142.16010-1-chenxux.di@intel.com>

Set RTE_ETH_DEV_CLOSE_REMOVE upon probe so all the private resources
 for the port can be freed by rte_eth_dev_close().

Signed-off-by: Di ChenxuX <chenxux.di@intel.com>
---
 doc/guides/rel_notes/release_19_11.rst |   4 +
 drivers/net/ixgbe/ixgbe_ethdev.c       | 167 +++++++++++++------------
 2 files changed, 89 insertions(+), 82 deletions(-)

diff --git a/doc/guides/rel_notes/release_19_11.rst b/doc/guides/rel_notes/release_19_11.rst
index 751606440..44011085d 100644
--- a/doc/guides/rel_notes/release_19_11.rst
+++ b/doc/guides/rel_notes/release_19_11.rst
@@ -77,6 +77,10 @@ New Features
 
   Added support for the ``RTE_ETH_DEV_CLOSE_REMOVE`` flag.
 
+* **Updated the Intel ixgbe driver.**
+
+  Added support for the ``RTE_ETH_DEV_CLOSE_REMOVE`` flag.
+
 
 Removed Items
 -------------
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 023b267d7..e6879c4b0 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -1245,6 +1245,11 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
 		return -ENOMEM;
 	}
 
+	/* Pass the information to the rte_eth_dev_close() that it should also
+	 * release the private port resources.
+	 */
+	eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
+
 	/* initialize the vfta */
 	memset(shadow_vfta, 0, sizeof(*shadow_vfta));
 
@@ -1311,73 +1316,12 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
 static int
 eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
-	struct ixgbe_hw *hw;
-	int retries = 0;
-	int ret;
-
 	PMD_INIT_FUNC_TRACE();
 
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
-	hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
-
-	if (hw->adapter_stopped == 0)
-		ixgbe_dev_close(eth_dev);
-
-	eth_dev->dev_ops = NULL;
-	eth_dev->rx_pkt_burst = NULL;
-	eth_dev->tx_pkt_burst = NULL;
-
-	/* Unlock any pending hardware semaphore */
-	ixgbe_swfw_lock_reset(hw);
-
-	/* disable uio intr before callback unregister */
-	rte_intr_disable(intr_handle);
-
-	do {
-		ret = rte_intr_callback_unregister(intr_handle,
-				ixgbe_dev_interrupt_handler, eth_dev);
-		if (ret >= 0) {
-			break;
-		} else if (ret != -EAGAIN) {
-			PMD_INIT_LOG(ERR,
-				"intr callback unregister failed: %d",
-				ret);
-			return ret;
-		}
-		rte_delay_ms(100);
-	} while (retries++ < (10 + IXGBE_LINK_UP_TIME));
-
-	/* cancel the delay handler before remove dev */
-	rte_eal_alarm_cancel(ixgbe_dev_interrupt_delayed_handler, eth_dev);
-
-	/* cancel the link handler before remove dev */
-	rte_eal_alarm_cancel(ixgbe_dev_setup_link_alarm_handler, eth_dev);
-
-	/* uninitialize PF if max_vfs not zero */
-	ixgbe_pf_host_uninit(eth_dev);
-
-	/* remove all the fdir filters & hash */
-	ixgbe_fdir_filter_uninit(eth_dev);
-
-	/* remove all the L2 tunnel filters & hash */
-	ixgbe_l2_tn_filter_uninit(eth_dev);
-
-	/* Remove all ntuple filters of the device */
-	ixgbe_ntuple_filter_uninit(eth_dev);
-
-	/* clear all the filters list */
-	ixgbe_filterlist_flush();
-
-	/* Remove all Traffic Manager configuration */
-	ixgbe_tm_conf_uninit(eth_dev);
-
-#ifdef RTE_LIBRTE_SECURITY
-	rte_free(eth_dev->security_ctx);
-#endif
+	ixgbe_dev_close(eth_dev);
 
 	return 0;
 }
@@ -1711,6 +1655,11 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
 		return -ENOMEM;
 	}
 
+	/* Pass the information to the rte_eth_dev_close() that it should also
+	 * release the private port resources.
+	 */
+	eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
+
 	/* Generate a random MAC address, if none was assigned by PF. */
 	if (rte_is_zero_ether_addr(perm_addr)) {
 		generate_random_mac_addr(perm_addr);
@@ -1762,30 +1711,12 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
-	struct ixgbe_hw *hw;
-
 	PMD_INIT_FUNC_TRACE();
 
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
-	hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
-
-	if (hw->adapter_stopped == 0)
-		ixgbevf_dev_close(eth_dev);
-
-	eth_dev->dev_ops = NULL;
-	eth_dev->rx_pkt_burst = NULL;
-	eth_dev->tx_pkt_burst = NULL;
-
-	/* Disable the interrupts for VF */
-	ixgbevf_intr_disable(eth_dev);
-
-	rte_intr_disable(intr_handle);
-	rte_intr_callback_unregister(intr_handle,
-				     ixgbevf_dev_interrupt_handler, eth_dev);
+	ixgbevf_dev_close(eth_dev);
 
 	return 0;
 }
@@ -2876,6 +2807,9 @@ ixgbe_dev_stop(struct rte_eth_dev *dev)
 	struct ixgbe_tm_conf *tm_conf =
 		IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
 
+	if (hw->adapter_stopped)
+		return;
+
 	PMD_INIT_FUNC_TRACE();
 
 	rte_eal_alarm_cancel(ixgbe_dev_setup_link_alarm_handler, dev);
@@ -2928,6 +2862,8 @@ ixgbe_dev_stop(struct rte_eth_dev *dev)
 	tm_conf->committed = false;
 
 	adapter->rss_reta_updated = 0;
+
+	hw->adapter_stopped = true;
 }
 
 /*
@@ -2998,13 +2934,16 @@ ixgbe_dev_close(struct rte_eth_dev *dev)
 {
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+	int retries = 0;
+	int ret;
 
 	PMD_INIT_FUNC_TRACE();
 
 	ixgbe_pf_reset_hw(hw);
 
 	ixgbe_dev_stop(dev);
-	hw->adapter_stopped = 1;
 
 	ixgbe_dev_free_queues(dev);
 
@@ -3012,6 +2951,55 @@ ixgbe_dev_close(struct rte_eth_dev *dev)
 
 	/* reprogram the RAR[0] in case user changed it. */
 	ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
+
+	dev->dev_ops = NULL;
+	dev->rx_pkt_burst = NULL;
+	dev->tx_pkt_burst = NULL;
+
+	/* Unlock any pending hardware semaphore */
+	ixgbe_swfw_lock_reset(hw);
+
+	/* disable uio intr before callback unregister */
+	rte_intr_disable(intr_handle);
+
+	do {
+		ret = rte_intr_callback_unregister(intr_handle,
+				ixgbe_dev_interrupt_handler, dev);
+		if (ret >= 0) {
+			break;
+		} else if (ret != -EAGAIN) {
+			PMD_INIT_LOG(ERR,
+				"intr callback unregister failed: %d",
+				ret);
+		}
+		rte_delay_ms(100);
+	} while (retries++ < (10 + IXGBE_LINK_UP_TIME));
+
+	/* cancel the delay handler before remove dev */
+	rte_eal_alarm_cancel(ixgbe_dev_interrupt_delayed_handler, dev);
+
+	/* uninitialize PF if max_vfs not zero */
+	ixgbe_pf_host_uninit(dev);
+
+	/* remove all the fdir filters & hash */
+	ixgbe_fdir_filter_uninit(dev);
+
+	/* remove all the L2 tunnel filters & hash */
+	ixgbe_l2_tn_filter_uninit(dev);
+
+	/* Remove all ntuple filters of the device */
+	ixgbe_ntuple_filter_uninit(dev);
+
+	/* clear all the filters list */
+	ixgbe_filterlist_flush();
+
+	/* Remove all Traffic Manager configuration */
+	ixgbe_tm_conf_uninit(dev);
+
+#ifdef RTE_LIBRTE_SECURITY
+	rte_free(dev->security_ctx);
+#endif
+
 }
 
 /*
@@ -5244,6 +5232,8 @@ ixgbevf_dev_start(struct rte_eth_dev *dev)
 	 */
 	ixgbevf_dev_link_update(dev, 0);
 
+	hw->adapter_stopped = false;
+
 	return 0;
 }
 
@@ -5255,6 +5245,9 @@ ixgbevf_dev_stop(struct rte_eth_dev *dev)
 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
+	if (hw->adapter_stopped)
+		return;
+
 	PMD_INIT_FUNC_TRACE();
 
 	rte_eal_alarm_cancel(ixgbe_dev_setup_link_alarm_handler, dev);
@@ -5289,6 +5282,8 @@ static void
 ixgbevf_dev_close(struct rte_eth_dev *dev)
 {
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -5304,6 +5299,14 @@ ixgbevf_dev_close(struct rte_eth_dev *dev)
 	 * after stop, close and detach of the VF
 	 **/
 	ixgbevf_remove_mac_addr(dev, 0);
+
+	dev->dev_ops = NULL;
+	dev->rx_pkt_burst = NULL;
+	dev->tx_pkt_burst = NULL;
+
+	rte_intr_disable(intr_handle);
+	rte_intr_callback_unregister(intr_handle,
+				     ixgbevf_dev_interrupt_handler, dev);
 }
 
 /*
-- 
2.17.1


  parent reply	other threads:[~2019-09-26  8:26 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-27  5:01 [dpdk-dev] [PATCH] drivers/net: " chenxux.di
2019-08-27  6:23 ` Ye Xiaolong
2019-09-05 11:03 ` [dpdk-dev] [PATCH v3 0/5] " Di ChenxuX
2019-09-05 11:03   ` [dpdk-dev] [PATCH v3 1/5] net/e1000: " Di ChenxuX
2019-09-05 11:03   ` [dpdk-dev] [PATCH v3 2/5] net/fm10k: " Di ChenxuX
2019-09-05 11:03   ` [dpdk-dev] [PATCH v3 3/5] net/i40e: " Di ChenxuX
2019-09-05 11:03   ` [dpdk-dev] [PATCH v3 4/5] net/ice: " Di ChenxuX
2019-09-05 11:03   ` [dpdk-dev] [PATCH v3 5/5] net/ixgbe: " Di ChenxuX
2019-09-19  2:47 ` [dpdk-dev] [PATCH v4 0/5] drivers/net: " Di ChenxuX
2019-09-19  2:47   ` [dpdk-dev] [PATCH v4 1/5] net/e1000: " Di ChenxuX
2019-09-25 15:41     ` Ye Xiaolong
2019-09-26  3:21       ` Di, ChenxuX
2019-09-19  2:47   ` [dpdk-dev] [PATCH v4 2/5] net/fm10k: " Di ChenxuX
2019-09-19  2:47   ` [dpdk-dev] [PATCH v4 3/5] net/i40e: " Di ChenxuX
2019-09-19  2:47   ` [dpdk-dev] [PATCH v4 4/5] net/ice: " Di ChenxuX
2019-09-19  2:47   ` [dpdk-dev] [PATCH v4 5/5] net/ixgbe: " Di ChenxuX
2019-09-23  2:27   ` [dpdk-dev] [PATCH v4 0/5] drivers/net: " Yang, Qiming
2019-09-26  7:30 ` [dpdk-dev] [PATCH v5 " Di ChenxuX
2019-09-26  7:30   ` [dpdk-dev] [PATCH v5 1/5] net/e1000: " Di ChenxuX
2019-09-26  7:30   ` [dpdk-dev] [PATCH v5 2/5] net/fm10k: " Di ChenxuX
2019-09-26  7:30   ` [dpdk-dev] [PATCH v5 3/5] net/i40e: " Di ChenxuX
2019-09-26  7:30   ` [dpdk-dev] [PATCH v5 4/5] net/ice: " Di ChenxuX
2019-09-26  7:30   ` Di ChenxuX [this message]
2019-09-26 10:42   ` [dpdk-dev] [PATCH v5 0/5] drivers/net: " Ye Xiaolong
2019-09-26 10:00 ` [dpdk-dev] [PATCH v6 " Di ChenxuX
2019-09-26 10:00   ` [dpdk-dev] [PATCH v6 1/5] net/e1000: " Di ChenxuX
2019-09-26 10:00   ` [dpdk-dev] [PATCH v6 2/5] net/fm10k: " Di ChenxuX
2019-09-26 10:00   ` [dpdk-dev] [PATCH v6 3/5] net/i40e: " Di ChenxuX
2019-09-26 10:00   ` [dpdk-dev] [PATCH v6 4/5] net/ice: " Di ChenxuX
2019-09-26 10:00   ` [dpdk-dev] [PATCH v6 5/5] net/ixgbe: " Di ChenxuX
2019-09-27  2:46   ` [dpdk-dev] [PATCH v6 0/5] drivers/net: " Yang, Qiming
2019-09-27  9:09 ` [dpdk-dev] [PATCH v7 " Di ChenxuX
2019-09-27  9:09   ` [dpdk-dev] [PATCH v7 1/5] net/e1000: " Di ChenxuX
2019-09-27  9:09   ` [dpdk-dev] [PATCH v7 2/5] net/fm10k: " Di ChenxuX
2019-09-27  9:09   ` [dpdk-dev] [PATCH v7 3/5] net/i40e: " Di ChenxuX
2019-09-27  9:09   ` [dpdk-dev] [PATCH v7 4/5] net/ice: " Di ChenxuX
2019-09-27  9:09   ` [dpdk-dev] [PATCH v7 5/5] net/ixgbe: " Di ChenxuX
2019-09-27 10:50   ` [dpdk-dev] [PATCH v7 0/5] drivers/net: " Ye Xiaolong

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=20190926073008.46653-6-chenxux.di@intel.com \
    --to=chenxux.di@intel.com \
    --cc=dev@dpdk.org \
    --cc=qiming.yang@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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).