From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8E8E5A0C4D; Thu, 17 Jun 2021 13:00:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2EA9C410F3; Thu, 17 Jun 2021 12:58:48 +0200 (CEST) Received: from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128]) by mails.dpdk.org (Postfix) with ESMTP id 6432441174 for ; Thu, 17 Jun 2021 12:58:46 +0200 (CEST) X-QQ-mid: bizesmtp46t1623927520tex607ex Received: from wxdbg.localdomain.com (unknown [183.129.236.74]) by esmtp6.qq.com (ESMTP) with id ; Thu, 17 Jun 2021 18:58:39 +0800 (CST) X-QQ-SSF: 01400000000000D0E000B00A0000000 X-QQ-FEAT: 0VmwRkEgV1FFuVSbpJlLEb8f/FC6WpQI2lODb35qZVouWtE8/eLLlI13s3a2o 7PG2F2tJBY8hQ7Ih9B8hUX8v2Ve+edDdg4bkT1/5YuRAkg5klBScFgcE34skjt4eAk+iMSo meXmibLWv1c2rlqpMhRFnaXB0IvluTCq8EvNRwp9pVe45jqXnx5w6uwQDkdQuKUERI89sxM SGlcE0rYf6jUTtKTSWEHm1Clg8XCp6TgQWpLrynaQZzDzWw+mTps6DimrTl+v73aHnf3v3/ K1ICY9DOLKtP4B6gvoah+U8IDBIzpTNMjNb6POnMCZSM0a12oDpbnvx0x+XgQSrADYR6/lW rGMGETYRHNQ4nyqp3pGWtCUHKqnVQtVcM8bSVTj X-QQ-GoodBg: 2 From: Jiawen Wu To: dev@dpdk.org Cc: Jiawen Wu Date: Thu, 17 Jun 2021 19:00:05 +0800 Message-Id: <20210617110005.4132926-20-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210617110005.4132926-1-jiawenwu@trustnetic.com> References: <20210617110005.4132926-1-jiawenwu@trustnetic.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybgforeign:qybgforeign5 X-QQ-Bgrelay: 1 Subject: [dpdk-dev] [PATCH v6 19/19] net/ngbe: support to close and reset device X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Support to close and reset device. Signed-off-by: Jiawen Wu --- drivers/net/ngbe/ngbe_ethdev.c | 61 ++++++++++++++++++++++++++++++++-- drivers/net/ngbe/ngbe_ethdev.h | 2 ++ drivers/net/ngbe/ngbe_rxtx.c | 20 +++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c index ef8ea5ecff..695c1d26c8 100644 --- a/drivers/net/ngbe/ngbe_ethdev.c +++ b/drivers/net/ngbe/ngbe_ethdev.c @@ -558,11 +558,66 @@ ngbe_dev_stop(struct rte_eth_dev *dev) static int ngbe_dev_close(struct rte_eth_dev *dev) { + struct ngbe_hw *hw = ngbe_dev_hw(dev); + 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(); - RTE_SET_USED(dev); + ngbe_pf_reset_hw(hw); + + ret = ngbe_dev_stop(dev); + + ngbe_dev_free_queues(dev); + + /* reprogram the RAR[0] in case user changed it. */ + ngbe_set_rar(hw, 0, hw->mac.addr, 0, true); + + /* Unlock any pending hardware semaphore */ + ngbe_swfw_lock_reset(hw); + + /* disable uio intr before callback unregister */ + rte_intr_disable(intr_handle); + + do { + ret = rte_intr_callback_unregister(intr_handle, + ngbe_dev_interrupt_handler, dev); + if (ret >= 0 || ret == -ENOENT) { + break; + } else if (ret != -EAGAIN) { + PMD_INIT_LOG(ERR, + "intr callback unregister failed: %d", + ret); + } + rte_delay_ms(100); + } while (retries++ < (10 + NGBE_LINK_UP_TIME)); + + rte_free(dev->data->mac_addrs); + dev->data->mac_addrs = NULL; + + rte_free(dev->data->hash_mac_addrs); + dev->data->hash_mac_addrs = NULL; + + return ret; +} + +/* + * Reset PF device. + */ +static int +ngbe_dev_reset(struct rte_eth_dev *dev) +{ + int ret; + + ret = eth_ngbe_dev_uninit(dev); + if (ret) + return ret; + + ret = eth_ngbe_dev_init(dev, NULL); - return -EINVAL; + return ret; } static int @@ -1101,6 +1156,8 @@ static const struct eth_dev_ops ngbe_eth_dev_ops = { .dev_infos_get = ngbe_dev_info_get, .dev_start = ngbe_dev_start, .dev_stop = ngbe_dev_stop, + .dev_close = ngbe_dev_close, + .dev_reset = ngbe_dev_reset, .link_update = ngbe_dev_link_update, .rx_queue_start = ngbe_dev_rx_queue_start, .rx_queue_stop = ngbe_dev_rx_queue_stop, diff --git a/drivers/net/ngbe/ngbe_ethdev.h b/drivers/net/ngbe/ngbe_ethdev.h index d576eef5d6..3893853645 100644 --- a/drivers/net/ngbe/ngbe_ethdev.h +++ b/drivers/net/ngbe/ngbe_ethdev.h @@ -67,6 +67,8 @@ ngbe_dev_intr(struct rte_eth_dev *dev) */ void ngbe_dev_clear_queues(struct rte_eth_dev *dev); +void ngbe_dev_free_queues(struct rte_eth_dev *dev); + void ngbe_dev_rx_queue_release(void *rxq); void ngbe_dev_tx_queue_release(void *txq); diff --git a/drivers/net/ngbe/ngbe_rxtx.c b/drivers/net/ngbe/ngbe_rxtx.c index 0801424245..62b1523c77 100644 --- a/drivers/net/ngbe/ngbe_rxtx.c +++ b/drivers/net/ngbe/ngbe_rxtx.c @@ -935,6 +935,26 @@ ngbe_dev_clear_queues(struct rte_eth_dev *dev) } } +void +ngbe_dev_free_queues(struct rte_eth_dev *dev) +{ + unsigned int i; + + PMD_INIT_FUNC_TRACE(); + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + ngbe_dev_rx_queue_release(dev->data->rx_queues[i]); + dev->data->rx_queues[i] = NULL; + } + dev->data->nb_rx_queues = 0; + + for (i = 0; i < dev->data->nb_tx_queues; i++) { + ngbe_dev_tx_queue_release(dev->data->tx_queues[i]); + dev->data->tx_queues[i] = NULL; + } + dev->data->nb_tx_queues = 0; +} + static int __rte_cold ngbe_alloc_rx_queue_mbufs(struct ngbe_rx_queue *rxq) { -- 2.21.0.windows.1