From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id AE5C0A00E6 for ; Mon, 2 Sep 2019 13:13:52 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BECB21E85D; Mon, 2 Sep 2019 13:13:36 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 3AD121E54B for ; Mon, 2 Sep 2019 13:13:34 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Sep 2019 04:13:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,459,1559545200"; d="scan'208";a="265996687" Received: from intel.sh.intel.com ([10.239.255.149]) by orsmga001.jf.intel.com with ESMTP; 02 Sep 2019 04:13:31 -0700 From: Di ChenxuX To: dev@dpdk.org Cc: Wenzhuo Lu , Beilei Xing , Qi Zhang , Yang Qiming , Di ChenxuX Date: Mon, 2 Sep 2019 10:27:42 +0000 Message-Id: <20190902102745.66695-3-chenxux.di@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190902102745.66695-1-chenxux.di@intel.com> References: <20190902102745.66695-1-chenxux.di@intel.com> Subject: [dpdk-dev] [PATCH 2/5] net/fm10k: release port upon close X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- drivers/net/fm10k/fm10k.h | 3 + drivers/net/fm10k/fm10k_ethdev.c | 122 ++++++++++++++++++------------- 2 files changed, 75 insertions(+), 50 deletions(-) diff --git a/drivers/net/fm10k/fm10k.h b/drivers/net/fm10k/fm10k.h index 916b856ac..40ded015c 100644 --- a/drivers/net/fm10k/fm10k.h +++ b/drivers/net/fm10k/fm10k.h @@ -133,6 +133,9 @@ struct fm10k_adapter { struct fm10k_hw hw; struct fm10k_hw_stats stats; struct fm10k_dev_info info; + + bool stopped; + bool closed; }; #define FM10K_DEV_PRIVATE_TO_HW(adapter) \ diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c index db4d72129..d21448776 100644 --- a/drivers/net/fm10k/fm10k_ethdev.c +++ b/drivers/net/fm10k/fm10k_ethdev.c @@ -1054,10 +1054,13 @@ static int fm10k_dev_start(struct rte_eth_dev *dev) { struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct fm10k_adapter *adapter = dev->data->dev_private; int i, diag; PMD_INIT_FUNC_TRACE(); + adapter->stopped = 0; + /* stop, init, then start the hw */ diag = fm10k_stop_hw(hw); if (diag != FM10K_SUCCESS) { @@ -1140,10 +1143,14 @@ static void fm10k_dev_stop(struct rte_eth_dev *dev) { struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct fm10k_adapter *adapter = dev->data->dev_private; struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev); struct rte_intr_handle *intr_handle = &pdev->intr_handle; int i; + if (adapter->stopped == 1) + return; + PMD_INIT_FUNC_TRACE(); if (dev->data->tx_queues) @@ -1171,6 +1178,8 @@ fm10k_dev_stop(struct rte_eth_dev *dev) rte_intr_efd_disable(intr_handle); rte_free(intr_handle->intr_vec); intr_handle->intr_vec = NULL; + + adapter->stopped = 1; } static void @@ -1194,28 +1203,6 @@ fm10k_dev_queue_release(struct rte_eth_dev *dev) } } -static void -fm10k_dev_close(struct rte_eth_dev *dev) -{ - struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private); - - PMD_INIT_FUNC_TRACE(); - - fm10k_mbx_lock(hw); - hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map, - MAX_LPORT_NUM, false); - fm10k_mbx_unlock(hw); - - /* allow 100ms for device to quiesce */ - rte_delay_us(FM10K_SWITCH_QUIESCE_US); - - /* Stop mailbox service first */ - fm10k_close_mbx_service(hw); - fm10k_dev_stop(dev); - fm10k_dev_queue_release(dev); - fm10k_stop_hw(hw); -} - static int fm10k_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete) @@ -2799,6 +2786,56 @@ fm10k_close_mbx_service(struct fm10k_hw *hw) hw->mbx.ops.disconnect(hw, &hw->mbx); } +static void +fm10k_dev_close(struct rte_eth_dev *dev) +{ + struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev); + struct rte_intr_handle *intr_handle = &pdev->intr_handle; + struct fm10k_adapter *adapter = dev->data->dev_private; + + PMD_INIT_FUNC_TRACE(); + + fm10k_mbx_lock(hw); + hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map, + MAX_LPORT_NUM, false); + fm10k_mbx_unlock(hw); + + /* allow 100ms for device to quiesce */ + rte_delay_us(FM10K_SWITCH_QUIESCE_US); + + /* Stop mailbox service first */ + fm10k_close_mbx_service(hw); + fm10k_dev_stop(dev); + fm10k_dev_queue_release(dev); + fm10k_stop_hw(hw); + + dev->dev_ops = NULL; + dev->rx_pkt_burst = NULL; + dev->tx_pkt_burst = NULL; + + /* disable uio/vfio intr */ + rte_intr_disable(intr_handle); + + /*PF/VF has different interrupt handling mechanism */ + if (hw->mac.type == fm10k_mac_pf) { + /* disable interrupt */ + fm10k_dev_disable_intr_pf(dev); + + /* unregister callback func to eal lib */ + rte_intr_callback_unregister(intr_handle, + fm10k_dev_interrupt_handler_pf, (void *)dev); + } else { + /* disable interrupt */ + fm10k_dev_disable_intr_vf(dev); + + rte_intr_callback_unregister(intr_handle, + fm10k_dev_interrupt_handler_vf, (void *)dev); + } + + adapter->closed = 1; +} + static const struct eth_dev_ops fm10k_eth_dev_ops = { .dev_configure = fm10k_dev_configure, .dev_start = fm10k_dev_start, @@ -3022,6 +3059,7 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev) struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private); struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev); struct rte_intr_handle *intr_handle = &pdev->intr_handle; + struct fm10k_adapter *adapter = dev->data->dev_private; int diag, i; struct fm10k_macvlan_filter_info *macvlan; @@ -3103,6 +3141,11 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev) &dev->data->mac_addrs[0]); } + /* Pass the information to the rte_eth_dev_close() that it should also + * release the private port resources. + */ + dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE; + /* Reset the hw statistics */ fm10k_stats_reset(dev); @@ -3199,46 +3242,25 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev) fm10k_MAC_filter_set(dev, hw->mac.addr, true, MAIN_VSI_POOL_NUMBER); + adapter->closed = 0; + adapter->stopped = 0; + return 0; } static int eth_fm10k_dev_uninit(struct rte_eth_dev *dev) { - struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private); - struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev); - struct rte_intr_handle *intr_handle = &pdev->intr_handle; + struct fm10k_adapter *adapter = dev->data->dev_private; + PMD_INIT_FUNC_TRACE(); /* only uninitialize in the primary process */ if (rte_eal_process_type() != RTE_PROC_PRIMARY) return 0; - /* safe to close dev here */ - fm10k_dev_close(dev); - - dev->dev_ops = NULL; - dev->rx_pkt_burst = NULL; - dev->tx_pkt_burst = NULL; - - /* disable uio/vfio intr */ - rte_intr_disable(intr_handle); - - /*PF/VF has different interrupt handling mechanism */ - if (hw->mac.type == fm10k_mac_pf) { - /* disable interrupt */ - fm10k_dev_disable_intr_pf(dev); - - /* unregister callback func to eal lib */ - rte_intr_callback_unregister(intr_handle, - fm10k_dev_interrupt_handler_pf, (void *)dev); - } else { - /* disable interrupt */ - fm10k_dev_disable_intr_vf(dev); - - rte_intr_callback_unregister(intr_handle, - fm10k_dev_interrupt_handler_vf, (void *)dev); - } + if (adapter->closed == 0) + fm10k_dev_close(dev); return 0; } -- 2.17.1