From patchwork Mon Sep 2 10:27:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chenxu Di X-Patchwork-Id: 58374 X-Patchwork-Delegate: xiaolong.ye@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7E6FC1E56A; Mon, 2 Sep 2019 13:13:34 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id EF6DB1D15B for ; Mon, 2 Sep 2019 13:13:31 +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:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,459,1559545200"; d="scan'208";a="265996683" Received: from intel.sh.intel.com ([10.239.255.149]) by orsmga001.jf.intel.com with ESMTP; 02 Sep 2019 04:13:29 -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:41 +0000 Message-Id: <20190902102745.66695-2-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 1/5] net/e1000: 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/e1000/e1000_ethdev.h | 1 + drivers/net/e1000/igb_ethdev.c | 142 +++++++++++++++++-------------- 2 files changed, 81 insertions(+), 62 deletions(-) diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h index 01ff9433b..67785fb67 100644 --- a/drivers/net/e1000/e1000_ethdev.h +++ b/drivers/net/e1000/e1000_ethdev.h @@ -282,6 +282,7 @@ struct e1000_adapter { struct e1000_vf_info *vfdata; struct e1000_filter_info filter; bool stopped; + bool closed; struct rte_timecounter systime_tc; struct rte_timecounter rx_tstamp_tc; struct rte_timecounter tx_tstamp_tc; diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c index fec2b4289..022c61c7c 100644 --- a/drivers/net/e1000/igb_ethdev.c +++ b/drivers/net/e1000/igb_ethdev.c @@ -843,6 +843,11 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev) rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]); + /* 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)); @@ -856,6 +861,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev) } hw->mac.get_link_status = 1; adapter->stopped = 0; + adapter->closed = 0; /* Indicate SOL/IDER usage */ if (e1000_check_reset_block(hw) < 0) { @@ -912,62 +918,17 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev) static int eth_igb_dev_uninit(struct rte_eth_dev *eth_dev) { - struct rte_pci_device *pci_dev; - struct rte_intr_handle *intr_handle; - struct e1000_hw *hw; struct e1000_adapter *adapter = E1000_DEV_PRIVATE(eth_dev->data->dev_private); - struct e1000_filter_info *filter_info = - E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private); PMD_INIT_FUNC_TRACE(); if (rte_eal_process_type() != RTE_PROC_PRIMARY) return -EPERM; - hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private); - pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); - intr_handle = &pci_dev->intr_handle; - - if (adapter->stopped == 0) + if (adapter->closed == 0) eth_igb_close(eth_dev); - eth_dev->dev_ops = NULL; - eth_dev->rx_pkt_burst = NULL; - eth_dev->tx_pkt_burst = NULL; - - /* Reset any pending lock */ - igb_reset_swfw_lock(hw); - - /* uninitialize PF if max_vfs not zero */ - igb_pf_host_uninit(eth_dev); - - /* disable uio intr before callback unregister */ - rte_intr_disable(intr_handle); - rte_intr_callback_unregister(intr_handle, - eth_igb_interrupt_handler, eth_dev); - - /* clear the SYN filter info */ - filter_info->syn_info = 0; - - /* clear the ethertype filters info */ - filter_info->ethertype_mask = 0; - memset(filter_info->ethertype_filters, 0, - E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter)); - - /* clear the rss filter info */ - memset(&filter_info->rss_info, 0, - sizeof(struct igb_rte_flow_rss_conf)); - - /* remove all ntuple filters of the device */ - igb_ntuple_filter_uninit(eth_dev); - - /* remove all flex filters of the device */ - igb_flex_filter_uninit(eth_dev); - - /* clear all the filters list */ - igb_filterlist_flush(eth_dev); - return 0; } @@ -1010,6 +971,7 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev) hw->vendor_id = pci_dev->id.vendor_id; hw->hw_addr = (void *)pci_dev->mem_resource[0].addr; adapter->stopped = 0; + adapter->closed = 0; /* Initialize the shared code (base driver) */ diag = e1000_setup_init_funcs(hw, TRUE); @@ -1038,6 +1000,11 @@ eth_igbvf_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)) { rte_eth_random_addr(perm_addr->addr_bytes); @@ -1079,26 +1046,15 @@ eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev) { struct e1000_adapter *adapter = E1000_DEV_PRIVATE(eth_dev->data->dev_private); - struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); PMD_INIT_FUNC_TRACE(); if (rte_eal_process_type() != RTE_PROC_PRIMARY) return -EPERM; - if (adapter->stopped == 0) + if (adapter->closed == 0) igbvf_dev_close(eth_dev); - eth_dev->dev_ops = NULL; - eth_dev->rx_pkt_burst = NULL; - eth_dev->tx_pkt_burst = NULL; - - /* disable uio intr before callback unregister */ - rte_intr_disable(&pci_dev->intr_handle); - rte_intr_callback_unregister(&pci_dev->intr_handle, - eth_igbvf_interrupt_handler, - (void *)eth_dev); - return 0; } @@ -1506,6 +1462,11 @@ eth_igb_stop(struct rte_eth_dev *dev) struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); struct rte_eth_link link; struct rte_intr_handle *intr_handle = &pci_dev->intr_handle; + struct e1000_adapter *adapter = + E1000_DEV_PRIVATE(dev->data->dev_private); + + if (adapter->stopped) + return; eth_igb_rxtx_control(dev, false); @@ -1547,6 +1508,8 @@ eth_igb_stop(struct rte_eth_dev *dev) rte_free(intr_handle->intr_vec); intr_handle->intr_vec = NULL; } + + adapter->stopped = 1; } static int @@ -1579,14 +1542,15 @@ static void eth_igb_close(struct rte_eth_dev *dev) { struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private); - struct e1000_adapter *adapter = - E1000_DEV_PRIVATE(dev->data->dev_private); struct rte_eth_link link; struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); struct rte_intr_handle *intr_handle = &pci_dev->intr_handle; + struct e1000_filter_info *filter_info = + E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private); + struct e1000_adapter *adapter = + E1000_DEV_PRIVATE(dev->data->dev_private); eth_igb_stop(dev); - adapter->stopped = 1; e1000_phy_hw_reset(hw); igb_release_manageability(hw); @@ -1610,6 +1574,42 @@ eth_igb_close(struct rte_eth_dev *dev) memset(&link, 0, sizeof(link)); rte_eth_linkstatus_set(dev, &link); + + dev->dev_ops = NULL; + dev->rx_pkt_burst = NULL; + dev->tx_pkt_burst = NULL; + + /* Reset any pending lock */ + igb_reset_swfw_lock(hw); + + /* uninitialize PF if max_vfs not zero */ + igb_pf_host_uninit(dev); + + rte_intr_callback_unregister(intr_handle, + eth_igb_interrupt_handler, dev); + + /* clear the SYN filter info */ + filter_info->syn_info = 0; + + /* clear the ethertype filters info */ + filter_info->ethertype_mask = 0; + memset(filter_info->ethertype_filters, 0, + E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter)); + + /* clear the rss filter info */ + memset(&filter_info->rss_info, 0, + sizeof(struct igb_rte_flow_rss_conf)); + + /* remove all ntuple filters of the device */ + igb_ntuple_filter_uninit(dev); + + /* remove all flex filters of the device */ + igb_flex_filter_uninit(dev); + + /* clear all the filters list */ + igb_filterlist_flush(dev); + + adapter->closed = 1; } /* @@ -3331,6 +3331,11 @@ igbvf_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; + struct e1000_adapter *adapter = + E1000_DEV_PRIVATE(dev->data->dev_private); + + if (adapter->stopped == 1) + return; PMD_INIT_FUNC_TRACE(); @@ -3353,6 +3358,8 @@ igbvf_dev_stop(struct rte_eth_dev *dev) rte_free(intr_handle->intr_vec); intr_handle->intr_vec = NULL; } + + adapter->stopped = 1; } static void @@ -3362,13 +3369,14 @@ igbvf_dev_close(struct rte_eth_dev *dev) struct e1000_adapter *adapter = E1000_DEV_PRIVATE(dev->data->dev_private); struct rte_ether_addr addr; + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); PMD_INIT_FUNC_TRACE(); e1000_reset_hw(hw); igbvf_dev_stop(dev); - adapter->stopped = 1; + igb_dev_free_queues(dev); /** @@ -3379,6 +3387,16 @@ igbvf_dev_close(struct rte_eth_dev *dev) memset(&addr, 0, sizeof(addr)); igbvf_default_mac_addr_set(dev, &addr); + + dev->dev_ops = NULL; + dev->rx_pkt_burst = NULL; + dev->tx_pkt_burst = NULL; + + rte_intr_callback_unregister(&pci_dev->intr_handle, + eth_igbvf_interrupt_handler, + (void *)dev); + + adapter->closed = 1; } static void